- 129 -
Comments
: This method performs the same operation as the
getElementsByTagName(name) method that is found on the Document node. The
Document node’s getElementsByTagName(name) searches the whole tree, whereas the
Element’s method searches only the subtree of the Element on which it was called.
Tree Management Examples
A few examples of using the Node and Document methods are presented here to bring
together some actual scenarios of DOM usage.
Creating Nodes
This example shows how to create a new Element node and insert it into the tree.
createElement(...) is used to create the new Element node, and insertBefore(...) is used
to insert it into the tree. The second parameter is set to null because we want to insert
new Element node to the end of the list. The xml property on the Document node, also
called xml, is used to show the resulting XML document. The xml property is a Microsoft
extension, which means it only works in MSXML (it is described in more detail in
Chapter
7
).