Java Reference
In-Depth Information
process. It is possible to append Node objects to a DocumentFragment object, which allows you to easily
and effi ciently insert all nodes contained within the DocumentFragment into the DOM tree.
The following code shows the use of a DocumentFragment:
var documentFragment = document.createDocumentFragment();
for (var i = 0; i < 1000; i++) {
var element = document.createElement(“div”);
var text = document.createTextNode(“Here is test for div #” + i);
element.setAttribute(“id”, i);
documentFragment.appendChild(element);
}
document.body.appendChild(documentFragment);
Without the DocumentFragment object, this code would update the DOM tree 1,000 times, thus degrad-
ing performance. With the DocumentFragment object, the DOM tree is updated only once.
The DocumentFragment object inherits the Node object, and as such has Node's properties and meth-
ods. It does not have any other properties or methods.
Element
Elements are the majority of objects, other than text, that you will encounter in the DOM.
Properties
Property Name
Description
Introduced
tagName
Returns the name of the element. The same as
Node.nodeName for this node type.
Level 1
Methods
Method Name
Description
Introduced
getAttribute(name)
Retrieves the attribute's value by
the specifi ed name.
Level 1
getAttributeNS(namespaceURI,
localName)
Returns the Attr object by local
name and namespace URI. Not
for HTML DOMs.
Level 2
getAttributeNode(name)
Returns the Attr object associ-
ated with the specifi ed name.
Returns null if no attribute by
that name exists.
Level 1
Continued
Search WWH ::




Custom Search