TreeWalker.firstChild()
The TreeWalker.firstChild()
method moves the current
Node
to the first visible child of the current node, and returns
the found child. It also moves the current node to this child. If no such child exists,
returns null
and the current node is not changed.
Syntax
node = treeWalker.firstChild;
Example
var treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
false
);
var node = treeWalker.firstChild(); // returns the first child of the root element, or null if none
Specifications
Specification |
---|
DOM Standard # dom-treewalker-firstchild |
Browser compatibility
BCD tables only load in the browser
See also
- The
TreeWalker
interface it belongs to.