Skip to content
Related Articles

Related Articles

HTML | DOM lastElementChild Property

View Discussion
Improve Article
Save Article
  • Last Updated : 11 Jul, 2022

The DOM lastElementChild property is used to return the last child element of the specified element or null if there is no last element. It is similar to lastChild property but the difference is that the lastChild property returns all last-child nodes i.e it includes text and comment nodes as well but on the other hand lastElementChild returns the last node as element node only. It is a read-only property. 



Return Value: It returns an object which represents the last child of an element. If there is no child element then it returns null. 



<!DOCTYPE html>
        DOM lastElementChild Property
    <!-- script to find last child element -->
        function Geeks() {
            var doc =
                document.getElementById("p").innerHTML = doc;
                document.getElementById("p").style.color = "white";
                document.getElementById("p").style.background = "green";
<body style="text-align: center;">
    <h1 style="color:green;">
            DOM lastElementChild Property
    <div id="GFG">
        <span>A computer science portal for geeks.</span>
    <button onclick="Geeks()">
        Click me!
    <p id="p"></p>


Before click on the button:


After click on the button: 


Supported Browsers: The browser supported by DOM lastElementChild property are listed below:

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Opera 10.0
  • Safari 4.0

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!