HTML DOM lastElementChild property
Example
Get in HTML
-
The last child element of the element:
var x = document.getElementById("myList").lastElementChild.innerHTML;
Try it »
Definition and Usage
The lastElementChild property returns the last child element of the specified element.
The difference between the lastElementChild property and the lastChild property is that lastChild returns the last child node as an element node, including text nodes or comment nodes (depending on which comes last), while lastElementChild returns the last child node as an element node (ignoring text and comment nodes).
This property is read-only.
Tip: Use the children property to return any child element of the specified element.
Tip: To return the first child element of the specified element, use firstElementChild attribute.
Browser support
| property | |||||
|---|---|---|---|---|---|
| lastElementChild | 2.0 | 9.0 | 3.5 | 4.0 | 10.0 |
Syntax
element.lastElementChild
Parameters
None
Return Value
| Type | Description |
|---|---|
| Object | Returns a Node object representing the last child element of the element, or null if there is no child element |
Technical Details
| DOM version | Core Level 3 Element Traversal |
|---|
More examples
Example
Obtain the
var
x
=
document
.
getElementById
(
"
myDIV
"
)
.
lastElementChild
.
tagName
;
document
.
getElementById
(
"
demo
"
)
.
innerHTML
=
x
;
Try it »
Example
Obtain the
Element object