I wanted to go through node to node in a web page, preserving the sequence.
eg. Below is the basic DOM:
<BODY> <DIV id ='1'> Test 1 </DIV> <DIV id='2'> Details about <SPAN id='3'> Execution </SPAN> </DIV> </BODY>
As in the previous example, I want to go through node on node ie
1st Traversal : <BODY> 2nd Traversal : <DIV id ='1'> 3rd Traversal : <DIV id='2'> 4rd Traversal : <SPAN id='3'>
My motive is to loop over all the nodes available on the current page and visit each node one by one, saying just nextnode (), while the traversal does not apply to parent and child relationships. Exepcted, it must visit each node following the sequence.
So my statement will be like this:
startnode //consider this is start node While ( startnode!=null ) { // will process on startnode startnode= startnode->nextnode(); // something like that to visit each node }
Does anyone know how to do this using jquery (preferred) or javascript, please share your recommendations.
thanks
-Pravin
source share