Gets a reference to the first child node in the childNodes collection of the object.
If the node is childless, null is returned.
Syntaxvar result = element.firstChild;
element.firstChild = value;
Return Value
Returns an object of type ElementElement
ExamplesThe following code example implements the firstChild attribute to get the first child element of an object.
<body>
<ul id ="oList">
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
<script type="text/javascript">
var oFirstChild = oList.firstChild;
</script>
</body>
The following example shows how the firstChild method will include white space nodes #text.
<p id="para-01">
First span
</p>
<p id="p2">first span, no whitespace</p>
<script type="text/javascript">
var p01 = document.getElementById('para-01');
alert(p01.firstChild.nodeName);
var p2=document.getElementById('p2');
alert(p2.firstChild.nodeName);
</script>
Syntax Standards information
Mozilla Developer Network : [Node.firstChild Article]
Microsoft Developer Network: [firstChild Property Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4