views:

54

answers:

3

hi,

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,'')
+1  A: 
$('html')[0].innerHTML.replace(/<!--|-->/g,'');
Daniel A. White
This seems pretty stupid, it does exactly the same only with more overhead.
adamse
True, but im answering the op's question.
Daniel A. White
this extra overhead is extremely minimal.
Paul Creasey
Plus, nothing is actually being done here. You're just replacing a string... You're not assigning the result to anything...
J-P
Um, he isn't doing anything with it in the original post.
Daniel A. White
A: 

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/

Code Monkey
+1  A: 

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.

slebetman