I am looking for a way to wrap, with jQuery, an element into a comment, like:
<!--
<div class="my_element"></div>
-->
and also a way to remove the comments.
Is this possible? because I couldn't find nothing related.
I am looking for a way to wrap, with jQuery, an element into a comment, like:
<!--
<div class="my_element"></div>
-->
and also a way to remove the comments.
Is this possible? because I couldn't find nothing related.
I'm impresed nobody gave the following solution. The following solution require a container. This container will have inside, the commented / uncommented code.
Example: https://jsfiddle.net/ConsoleTVs/r6bm5nhz/
You can comment the element out by doing the following:
DEMO: http://jsfiddle.net/dirtyd77/THBpD/27/
For wrapping?
Not sure how successful you'd be finding the comments once wrapped though. A text search on the body element using regular expressions is an option.
Or this - is it possible to remove an html comment from dom using jquery
To wrap an element with comment, or more specifically to replace an element with a comment node having that element's HTML:
To switch it back:
If you don't have the reference to the comment node then you need to traverse the DOM tree and check
nodeType
of each node. If its value is 8 then it is a comment.For example:
JavaScript: