DOM Node.firstChild Property
The firstChild property returns the first child node of a node, which may be a text node. lastChild returns the last one.
Description
The read-only firstChild property returns the node's first child, and lastChild its last. Because white space between tags creates text nodes, the result is often a text node rather than the element you expect; use firstElementChild and lastElementChild to skip them.
Because they return any kind of node, they're useful when you specifically need text nodes, such as reading or replacing the text at the start of an element without affecting its child elements. Both return null for an element with no children.
When writing HTML, white space between tags, including line breaks and indentation, becomes text nodes, so even <ul> elements that look as if they only contain <li> elements usually start with a text node.
Syntax
node.firstChild
node.lastChildValue
The first (or last) child node, or null if there are no children.
Example
Browser Support
The following information will show you the current browser support for the Node.firstChild property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





