|
How to traverse the DOM Tree with JavascriptJeffrey P. Bigham |
|
Related ArticlesRelated Ads |
To make dynamic pages it is often quite useful to be able to traverse the DOM tree of the current HTML document. This interface allows you to update individual branches and leaves and restructure the page however you like. Below is a simpel recursive function that will visit every node in the tree and shows how to determine that you've reached a leaf node. The code is called with the traverseDomTree() function, which finds the body element and then calls the recursive version of the function, which keeps track of the curr_element and the level of the tree that the code has reached. In customizing this, not all of this functionality will be required.
|
|
|
||