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

  • Home
  • SEARCH
  • 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 208449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:49:35+00:00 2026-05-11T17:49:35+00:00

I am traversing a HTML document using javascript DOM. I want make a list

  • 0

I am traversing a HTML document using javascript DOM. I want make a list (an array actually) of all nodes/elements and their values. I found a script for traversing DOM, but how do I store each node value in an array. I can’t seem to find the unique identifier for a node. Anyone has any pointers? I was thinking of xpath or something.

Is it a good idea to consider xpath for node as the unique identifier. If so how do I get xpath of a element while traversing the DOM?

  • 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-11T17:49:35+00:00Added an answer on May 11, 2026 at 5:49 pm

    As programmer born and brought up in the world of C and C++, my first answer to this kind of question would have been “store their addresses in the array!”. But after a couple years of messing around with the web way of things, I can give the right answer:

    In javascript, you can directly store the references to the objects in the array.
    And no, xpath is not a good idea for this; using references is simpler and better.
    So a direct answer to your question is: there is no unique identifier for a DOM element/node except itself.

    In javascript, all objects are passed around by reference. So here’s a sample code for how to do it:

    var theArray = [];
    var theNodeToTraverse = document.getElementById('domelementtosearch');
    
    traverseAndStore(theNodeToTraverse);
    
    function traverseAndStore( node )
    {
        if( node==null) return;
        theArray[ theArray.length ] = node;
        for( i=0; i<node.childNodes.length; i++ )
            traverseAndStore( node.childNodes[i] );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try looking here: http://blogs.msdn.com/dancre/archive/2006/10/11/datamodel-view-viewmodel-pattern-series.aspx Hope it helps :-) May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer Okay, found the answer. For each column I need to… May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer I suppose that what you want is to convert a… May 11, 2026 at 10:08 pm

Related Questions

I am working on an algorithm that will try to pick out, given an
I am considering Erlang as a potential for my upcoming project. I need a
I've got quite a few GreaseMonkey scripts that I wrote at my work which
I have a linked list of around 5000 entries (NOT inserted simultaneously), and I
I'm storing a bunch of supposedly-unique item IDs as a key and the file

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.