Get child node by index in JavaScript
Description
The following code shows how to get child node by index.
Example
<!DOCTYPE HTML>
<html>
<body>
<div id="results">
<code><code>
<p></p>
</div><!--from w ww.j a v a2s. com-->
<script>
var resultsElement = document.getElementById("results");
document.writeln(resultsElement.nodeType);
document.writeln(resultsElement.nodeName);
var secondChild = resultsElement.childNodes.item(1);
document.writeln(secondChild.nodeName);
</script>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Get
Access data attributes in HTML element in J...
Behave differently for different element id...
Call getElementById for duplicate id in Jav...
Clone a HTML element and output its inner h...
Clone a node in JavaScript
Compare node type to a numeric value in Jav...
Compare the value of innerText and innerHTM...
Convert NodeList to an Array in JavaScript
Convert a NodeList to an array in Internet ...
Create a HTML element in JavaScript
Create new HTML element and set its inner t...
Deal with null sibling value in JavaScript
Deal with the single child with lastChild i...
Get all attributes for a HTML element in Ja...
Get attribute from a HTML element in JavaSc...
Get disabled from element in JavaScript
Get element array by class name in JavaScri...
Get element array length returned by getEle...
Get element by id in JavaScript
Get elements by tag name with getElementsBy...
Get hidden from element in JavaScript
Get id from element in JavaScript
Get lang from element in JavaScript
Get tag name from element in JavaScript
Get tags by name using getElementsByName fu...
Get the first child for an element in JavaS...
Get the inner html for a HTML element in Ja...
Get the inner text for a HTML element in Ja...
Get the nodeName and nodeValue in JavaScrip...
Get the outer html for a HTML element in Ja...
Get the parent node in JavaScript
Get the previous sibling and next sibling i...
Get the reference to entire document in Jav...
List attribute for a HTML element by name a...
Loop through the array returned by getEleme...
Reference a button directly using its id in...
Show nodes are stored in a NodeList in Java...
Use length to get the last child in JavaScr...
Access data attributes in HTML element in J...
Behave differently for different element id...
Call getElementById for duplicate id in Jav...
Clone a HTML element and output its inner h...
Clone a node in JavaScript
Compare node type to a numeric value in Jav...
Compare the value of innerText and innerHTM...
Convert NodeList to an Array in JavaScript
Convert a NodeList to an array in Internet ...
Create a HTML element in JavaScript
Create new HTML element and set its inner t...
Deal with null sibling value in JavaScript
Deal with the single child with lastChild i...
Get all attributes for a HTML element in Ja...
Get attribute from a HTML element in JavaSc...
Get child node by index in JavaScript
Get dir from element in JavaScriptGet disabled from element in JavaScript
Get element array by class name in JavaScri...
Get element array length returned by getEle...
Get element by id in JavaScript
Get elements by tag name with getElementsBy...
Get hidden from element in JavaScript
Get id from element in JavaScript
Get lang from element in JavaScript
Get tag name from element in JavaScript
Get tags by name using getElementsByName fu...
Get the first child for an element in JavaS...
Get the inner html for a HTML element in Ja...
Get the inner text for a HTML element in Ja...
Get the nodeName and nodeValue in JavaScrip...
Get the outer html for a HTML element in Ja...
Get the parent node in JavaScript
Get the previous sibling and next sibling i...
Get the reference to entire document in Jav...
List attribute for a HTML element by name a...
Loop through the array returned by getEleme...
Reference a button directly using its id in...
Show nodes are stored in a NodeList in Java...
Use length to get the last child in JavaScr...