O'Reilly logo

Learning JavaScript by Shelley Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying the Tree

The document is the owner/parent of all page elements. Because of this, most factory methods to create instances of new elements are methods on the Core document object. The Node, though, maintains the navigation within the Core API. This supports the hierarchical structure of the document tree, in which each node has a relationship to other nodes, and navigation follows this natural structure: parent/child, sibling/sibling. Finally, the Element provides a way to access elements within context in order to apply changes to nested elements. All three are essential objects when it comes to modifying the document tree.

The document factory methods, and the type of Core objects they create, are listed in Table 10-1. This also provides a brief introduction to several of the Core objects.

Table 10-1. Factory methods of the Document object

MethodObject createdDescription
createElement(tagname)
Element
Creates an element that is cast to the specific tag
createDocumentFragment
DocumentFragment
The DocumentFragment is a lightweight document, used when extracting a section of the document tree
createTextNode(data)
Text
Holds any text in the page
createComment(data)
Comment
XML comment
createCDATASection(data)
CDATASection
CDATA section
createProcessingInstructions(target,data)
ProcessingInstruction
XML processing instruction
createAttribute(name)
Attr
Element attribute
createEntityReference(name)
EntityReference
Placeholder for an element to be placed later
createElementNS ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required