The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.
The items in the NodeList are accessible via an integral index, starting from 0.
Note that this object is implemented and supported by the web browser and results of its use may vary.
The number of nodes in this map. The range of valid child node indices is 0 to length-1 inclusive.
This is a readonly attribute.
Example:
<div id="doc">
<div>
Text in the first DIV.
</div>
<div id="DDD" class="secondClass">
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span id="SSS">element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var collection = main.getElementsByTagName('DIV');
Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var collection = main.getElementsByTagName('DIV');
var output1 = collection.item(2).firstChild.nodeValue;
var output2 = collection[2].firstChild.nodeValue;
Parameters:
index
-
The Index into this map.
Return:
Node - The node at the indexth position in the NamedNodeMap, or null if that is not a valid index.