Tutorial :How to use this with JQuery



Question:

how do i use this code with jquery, i know it's easy but it doesn't work for me.

document.getElementsByTagName('html')[0].innerHTML.replace(/<!--|-->/g,'')  


Solution:1

$('html')[0].innerHTML.replace(/<!--|-->/g,'');  


Solution:2

If your intention is to generate a new string where all <!-- and --> are removed then your code works just fine. If not then you probably should be reminded that in javascript, a String's replace() method does not replace anything in that string, it generates a new string. So:

var html = document.getElementsByTagName('html')[0];  html.innerHTML = html.innerHTML.replace(/<!--|-->/g,'');  

But your question is very odd. Why would you want to do this? Perhaps you want to uncomment some commented out code? This does not look like something that is safe to do.


Solution:3

This should work for you. Remember you can use javascript and jQuery together. Try this:

$("<html>").html($("<html>").html().replace(/<!--|-->/g,''));  

Probably not the most elegant solution, but should work. Are you familiar with:

http://visualjquery.com/


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »