DOM tree?

A

Alex

What does it mean to "walk the DOM tree"? How do you use it?

I hear programmers using this term loosely and I'm not sure what it
means. I understand that DOM means Document Object Module and that they
are referencing the additional elements whithin (X)HTML.

But the "TREE" part throws me off...

thanks.

-ac
 
D

David Dorward

Alex said:
What does it mean to "walk the DOM tree"? How do you use it?

Generally, by finding the node(s) you want by starting somewhere and using
repeated access of parentNode/childNodes/firstChild/etc properties.
I hear programmers using this term loosely and I'm not sure what it
means. I understand that DOM means Document Object Module and that they
are referencing the additional elements whithin (X)HTML.

What's additional about them?
But the "TREE" part throws me off...

The HTML element node branches into a HEAD element node and a BODY element
node which branch into other nodes, etc.
 
R

RobG

Alex said:
What does it mean to "walk the DOM tree"? How do you use it?

To understand the concept of the document object model (DOM) tree, use
Firefox's DOM Inspector to look at a simple HTML document. All the
elements and nodes are laid out in a hierarchical structure, or tree.

e.g.

HTML--
|-head
| |
| |-title
| |
| |-script
|
|-body
|
|-#text
|
|-p
| |
| |-#text
| |
| |-span
| |
| |-#text
|
|-#text
|
|-p
|
|-#text


Walking the DOM is identifying nodes of the tree using parentNode/childNode
and firstChild/lastChild to go up/down the tree and
nextSibling/previousSibling to identify adjacent nodes.

There are also various collections that can be used too, such as
childNodes, (table) rows and cells, forms, elements, images, etc.

Important documents are the W3C DOM Core and HTML specifications:

Core:
<URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html>

HTML:
I hear programmers using this term loosely and I'm not sure what it
means. I understand that DOM means Document Object Module and that they

DOM is document object _model_.

are referencing the additional elements whithin (X)HTML.

XHTML is just HTML written to conform to XML rules, there are no
"additional elements".


[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top