If I have that
<!-- some comment -->
How do I get this element and change the content with javascript?
And if I have a code inside that and I want to delete the tag of comments how can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using a NodeIterator (IE >= 9)
The best method is to use a dedicated NodeIterator instance iterating all comments contained in a given root element.
See it in action!
Using a custom-made DOM traversal (to support IE < 9 as well)
If you have to support older browsers (e.g. IE <9), you need to traverse the DOM yourself and extract those elements whose node type is
Node.COMMENT_NODE.See it in action!
Extracting a node’s contents and delete it
Independent of the way you choose from above, you receive the same node DOM objects.
Accessing a comment’s contents is as easy as
commentObject.nodeValue.Deleting a comment is a bit more verbose:
commentObject.parentNode.removeChild(commentObject)