Export (0) Print
Expand All

createNodeIterator method

Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.

Document Object Model (DOM) Level 2 Traversal and Range Specification, Section 1.2Internet Explorer 9

Syntax

var ppNodeIterator = document.createNodeIterator(pRootNode, ulWhatToShow, pFilter, fEntityReferenceExpansion);

Parameters

pRootNode [in]

Type: Node

The root element or node to start traversing on.

ulWhatToShow [in]

Type: Integer

The type of nodes or elements to appear in the node list. For more information, see whatToShow.

pFilter [in]

Type: Variant

A custom NodeFilter function to use. For more information, see filter. Use null for no filter.

fEntityReferenceExpansion [in]

Type: Boolean

A flag that specifies whether entity reference nodes are expanded. For more information, see expandEntityReferences.

ppNodeIterator [out, retval]

Type: IDOMNodeIterator

Returns a NodeIterator object.

Return value

Type: IDOMNodeIterator

Returns a NodeIterator object.

Exceptions

ExceptionCondition
NotSupportedError

pRootNode is null. Versions earlier than Internet Explorer 10 will throw the exception as NOT_SUPPORTED_ERR.

Standards information

Remarks

Use the createNodeIterator method when you want to focus on node content because NodeIterator traverses a flat list of nodes in the document structure.

Examples

The following code example shows how to use NodeIterator objects to find and remove references. The iterator returns all text nodes from the document body and searches for Monday in text and id attributes of parent nodes. The script matches text by using the wholeText object of the node.


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function noMondays()
{
    var ni = document.createNodeIterator(document.body, NodeFilter.SHOW_TEXT, null, false);
                
    var textNode = ni.nextNode();
    while (textNode) {
        if (textNode.wholeText.match('Monday') || 
            textNode.parentNode.getAttribute('id') == 'Monday')
        {
            textNode.parentNode.removeChild(textNode);
        }
        textNode = ni.nextNode();
    }
}
function refresh()                 
{
    window.location.reload( false );    // Reload our page.
}
</script>
</head>
<body>
    <p>Monday, Joe bought a turkey.</p>
    <p>Tuesday, Bill bought a pound of nails.</p>
    <div>Chuck called in sick Monday.</div>
    <p id="Monday">CALL supplier today!</p>
    <p>Wednesday's delivery was delayed.</p>
    <button onclick="refresh()">Reload</button>
    <button onclick="noMondays()">Lose Mondays</button>
</body>
</html>

See also

document

 

 

Show:
© 2014 Microsoft