currentNode
Summary
Sets or retrieves where the current node in a filtered TreeWalker hierarchy is positioned.
Property of dom/TreeWalkerdom/TreeWalker
Syntax
var node = walker.currentNode;
walker.currentNode = value;
Return Value
Returns an object of type DOM NodeDOM Node
The currentNode of the TreeWalker object.
Examples
<div id="divcontent">
<p>Some text</p>
<b>Bold text</b>
</div>
<script type="text/javascript">
var rootnode=document.getElementById('divcontent');
var walker=document.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, null, false);
//Alert the starting node Tree Walker currently points to (root node)
alert(walker.currentNode.tagName) //alerts DIV (with id=divcontent)
//Step through and alert all child nodes
while (walker.nextNode())
alert(walker.currentNode.tagName) //alerts P, SPAN, and B.
//Go back to the first child node of the collection and alert it
walker.currentNode=rootnode; //reset TreeWalker pointer to point to root node
alert(walker.firstChild().tagName); //alerts P
</script>
Notes
Remarks
currentNode will never return null in Windows Internet Explorer 9, even when the traversing method returns null.
Syntax
Standards information
Related specifications
- DOM
- Living Standard
Attributions
Mozilla Developer Network : [TreeWalker.currentNode Article]
Microsoft Developer Network: [currentNode Property Article]