Get the HTML content of the last child element of an <ul> element:
The result of x will be:
More "Try it Yourself" examples below.
The firstElementChild property returns the last child element of the specified element.
The difference between this property and lastChild, is that lastChild returns the last child node as an element node, a text node or a comment node (depending on which one's last), while lastElementChild returns the last child node as an element node (ignores text and comment nodes).
This property is read-only.
Tip: Use the children property to return any child element of a specified element.
Tip: To return the first child element of a specified element, use the firstElementChild property.
Property | |||||
---|---|---|---|---|---|
lastElementChild | 2.0 | 9.0 | 3.5 | 4.0 | 10.0 |
Return Value: | A Node object, representing the last child element of an element, or null if there are no child elements |
---|---|
DOM Version | Core Level 3 Element Traversal |
Get the tag name of the last child element of a <div> element:
The result of x will be:
Get the text of the last child element of a <select> element:
The result of x will be: