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 6142077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:20:18+00:00 2026-05-23T18:20:18+00:00

I’m working on a side project at work which requires me to write some

  • 0

I’m working on a side project at work which requires me to write some javascript code. Unfortunately I’m very new to the javascript world and am learning as I go.

So part of what I have to do requires me to find certain comments on the page, and I am using the following line to get all the comments first:

var arr = document.getElementsByTagName("!");

This works perfectly in IE8 and returns an array of all the comments on the page. However this returns an empty array in Google Chrome and I can see an uncaught TypeError (Presumably due to operations being performed on the empty array) when I open up the Developer Console.

Any ideas why this is not working on both browsers? Is this some sort of unsupported operation that I shouldn’t be using, or am I just misusing it?

Any help, or pointers in some direction are greatly appreciated! Thank you!

Clarification:
I am doing this in order to manipulate a sharepoint page. That actual intent of this script is to hide a table row that an input element is in. So to do that I need to first find the element, but I can’t do that since the attributes for it are basically garbled junk:

<input name="ctl00$m$g_edc51673_bad2_46d5_9a65_e71137e56558$ctl00$ctl04$ctl00$ctl00$ctl‌​00$ctl04$ctl00$ctl00$TextField"
type="text" value="Title" maxlength="255"
id="ctl00_m_g_edc51673_bad2_46d5_9a65_e71137e56558_ctl00_ctl04_ctl00_ctl00_ctl00_‌​ctl04_ctl00_ctl00_TextField"
title="Title" class="ms-long">

(I put in newlines in some places to make it easier to read, but that’s all on one line in the source (not that that makes a difference))

So anyway, I can’t really use that find the control I’m looking for. And you may say that that has some structure what with the type of the input consistently at the end of the garbage, and the title attribute and all that. But it isn’t. Yours truly, Microsoft, does this for some controls, but not for others.

BUT! They are absolutely consistent with providing comments right before this garbled junk that have the name of the element in them, and if I can grab that comment I can foo.parenNode over to what I want.

  • 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-05-23T18:20:18+00:00Added an answer on May 23, 2026 at 6:20 pm

    You can traverse the DOM starting at the node, document and iterating each node’s childNodes array. When you find a node, you can test for the nodeType==8

    Here are links to

    childNodes

    nodeType

    document.createTextNode

    And a small example

    <html>
    <head>
    </head>
    <body>
    <ul>
    <li>junk
    <li>text
    <!-- comment 1 -->
    <li>hi
    <li>hello
    <li>world
    </ul>
    <br/>
    <!-- comment 2 -->
    <script>
    window.onload=findcommentsstart
    var msgs = [];
    function findcommentsstart()
    {
        findcomments(document);
        var txt = document.createTextNode(msgs.join("\n"));
        document.getElementsByTagName("body")[0].appendChild(txt);
    }
    
    function findcomments(d)
    {
        if(!d)
            return;
        if(d.nodeType==8)
            msgs.push("found a comment node " + d.data);
        if(!d.childNodes)
            return;
        for(var i=0;i<d.childNodes.length;i++)
            findcomments(d.childNodes[i]);
    }
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.