www.webdeveloper.com
Results 1 to 3 of 3

Thread: What is the unique identifier for a DOM element/node

  1. #1
    Join Date
    May 2009
    Posts
    6

    What is the unique identifier for a DOM element/node

    I am traversing a HTML document using javascript DOM. I want make a list (an array actually) of all nodes/elements and thier values. On w3schools website 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 sumthing.

    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.

    Thanks in advance for your help

  2. #2
    Join Date
    Sep 2008
    Posts
    95
    Hello,

    I'm not sure I fully understand what you're looking to do. If you're traversing the DOM array, can you not just do something like this?

    Code:
    var myArray=new Array();
    
    function traverse(){
    
    //for each element in the DOM myArray.push(thisElement.id);
    }
    i'm not sure what you mean by "and their values." Are you looking for the style, etc info in the tag? Or for innerHTML?

    Regards,
    Josh

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by asacool View Post
    I am traversing a HTML document using javascript DOM. I want make a list (an array actually) of all nodes/elements and thier values.
    Too vague. You must consider the fact that not all the DOM nodes have values (in fact nodeValue). In fact, what do you mean by values?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles