Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:57:09+00:00 2026-06-14T06:57:09+00:00

If I have that <!– some comment –> How do I get this element

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:57:10+00:00Added an answer on June 14, 2026 at 6:57 am

    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!

    function filterNone() {
        return NodeFilter.FILTER_ACCEPT;
    }
    
    function getAllComments(rootElem) {
        var comments = [];
        // Fourth argument, which is actually obsolete according to the DOM4 standard, is required in IE 11
        var iterator = document.createNodeIterator(rootElem, NodeFilter.SHOW_COMMENT, filterNone, false);
        var curNode;
        while (curNode = iterator.nextNode()) {
            comments.push(curNode.nodeValue);
        }
        return comments;
    }
    
    window.addEventListener("load", function() {
        console.log(getAllComments(document.body));
    });
    

    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!

    // Thanks to Yoshi for the hint!
    // Polyfill for IE < 9
    if (!Node) {
        var Node = {};
    }
    if (!Node.COMMENT_NODE) {
        // numeric value according to the DOM spec
        Node.COMMENT_NODE = 8;
    }
    
    function getComments(elem) {
      var children = elem.childNodes;
      var comments = [];
    
      for (var i=0, len=children.length; i<len; i++) {
        if (children[i].nodeType == Node.COMMENT_NODE) {
          comments.push(children[i]);
        }
      }
      return comments;
    }
    

    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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have that Jquery code: $('input[name*=fotos[]]').each(function (i, ele) { alert(ele.val()); }); but I get
I have this php code that should take all the php files in a
I have that JavaScript code: var state = 'hidden'; function Show_Picture() { if (state
I have that problem, in html I have this code: <div> <div class='category' style=display:block>
I have that text : <a href=/extend/themes/bizway>BizWay</a> And i want to use regular expression
I would like to have that the height of a canvas change automatically. When
I have that code: jQuery(document).ready(function () { // binds form submission and fields to
I have that site : http://ougk.gr and I want on the navigation to have
I have that code: #!/usr/bin/python -u localport = 9876 import sys, re, os from
I have that code : while(!lastPage && currentPage < maxPageSize){ StringBuilder request = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.