The firstChild
property returns the first
child node of the specified node, as a Node object.
firstChild |
Yes | Yes | Yes | Yes | Yes |
node.firstChild
The first child of the node, as a Node object.
The following code shows how to get the first child node of the document.
<!DOCTYPE html>
<html>
<body>
<p id="demo">test</p>
<!-- www .j a v a 2 s. co m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction()
{
var x=document.getElementById("demo");
x.innerHTML=document.firstChild.nodeName;
}
</script>
</body>
</html>
The code above is rendered as follows: