Java Reference
In-Depth Information
sports.children // this will only contain paragraph
elements
<< HTMLCollection [ <p>, <p>, <p> ]
sports.children.length
<< 3
The firstChild property returns the first child of a node:
sports.firstChild
<< #text "
"
And the lastChild property returns the last child of a node:
sports.lastChild
<< #text "
"
Be careful when using these properties―the first or last child node can often be a text node,
even if it's just an empty string generated by some whitespace.
For example, you might expect the first child node of the sports element to be the swim
element and the last child to be the run element, but it is in fact a text node, generated by
the whitespace characters in between the <section> and <p> tags:
The parentNode property returns the parent node of an element. The following code re-
turns the sports node because it is the parent of the bike node:
bike.parentNode;
<< <section id="sports">
The nextSibling property returns the next adjacent node (that is, the same parent). It
will return null if the node is the last child node of that parent:
bike.nextSibling;
<< #text "
"
Search WWH ::




Custom Search