Method Summary

Field Detail

length

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');

var output = collection.length;

Method Detail

item

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.