just wondering if there was a way to remove an html comment using jquery.
<!-- <div id="main">Some text </div> -->
thanks
just wondering if there was a way to remove an html comment using jquery.
<!-- <div id="main">Some text </div> -->
thanks
Comments are not really "in" the DOM in the first place, so I'm going to go out on a limb and say "no". I think I'm really just trying to get Cletus or somebody to drop in and blow my mind with a way to do it :-)
I'm almost certain comments aren't actually part of the DOM. They're part of the original HTML code, but when browsers convert it to the DOM, they get stripped as they serve no purpose for rendering.
Not that I know of. But I don't understand what the use of it would be. A comment will only be seen if you view the pagesource, and most (if not all) browsers that have a view source option will by default give you the source before javascript loading.
Try this:
$('*').contents().each(function() {
if(this.nodeType == 8) {
$(this).remove()
}
});
EDIT: This removes the elements from the DOM. Browsers often store a copy of the original page source that is accessible through a menu item. This doesn't get updated.
If you want to hide your comments, you could always insert your entire HTML markup (with comments) into the DOM using javascript. The javascript could, of course, be viewed, but it is a step removed from the first place people would look.