JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

15.3.1 Documents As Trees of Nodes

15.3.1 Documents As Trees of Nodes


The Document object, its Element objects, and the Text objects that represent runs of text in the document are all Node objects. Node defines the following important properties:

parentNode

The Node that is the parent of this one, or null for nodes like the Document object

that have no parent.

childNodes

A read-only array-like object (a NodeList) that is a live representation of a Node’s child nodes.

firstChild, lastChild

The first and last child nodes of a node, or null if the node has no children. nextSibling, previousSibling

The next and previous sibling node of a node. Two nodes with the same parent are

siblings. Their order reflects the order in which they appear in the document. These

properties connect nodes in a doubly linked list.

15.3 Document Structure and Traversal | 371

nodeType

The kind of node this is. Document nodes have the value 9. Element nodes have the value 1. Text nodes have the value 3. Comments nodes are 8 and Document-Fragment nodes are 11.

nodeValue

The textual content of a Text or Comment node.

nodeName

The tag name of an Element, converted to uppercase.

Using these Node properties, the second child node of the first child of the Document can be referred to with expressions like these:

document.childNodes[0].childNodes[1] document.firstChild.firstChild.nextSibling

Suppose the document in question is the following:

TestHello World!

Then the second child of the first child is theelement. It has a nodeType of 1 and a nodeName of “BODY”.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/27925.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1