Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App

HTML DOM lastElementChild Property

Last Updated : 30 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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 the 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 an element node only. It is a read-only property. 

Syntax:

element.lastElementChild

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

Example: In this article, we will use DOM lastElementChild property

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

Output: 

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

V

Vishal Chaudhary 2
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-DOM

Similar Reads

    HTML DOM click() Method
    The click() method is used to simulate the mouse click on an element. This method works exactly the same as the element is manually clicked. Syntax: HTMLElementObject.click() Parameters: No parameters required. Return Value: No return value. Example: In this example, when the cursor goes over the ra
    1 min read
    HTML DOM scrollTop Property
    The DOM scrollTop property is used to return or set the number of pixels an element is scrolled vertically. If the element's content doesn't generate a scroll bar, then its scrollTop value is 0. Syntax: It returns the scrollTop property.element.scrollTopIt is used to set the scrollTop propertyelemen
    2 min read
    HTML DOM isSameNode() Method
    The isSameNode() method checks whether the two nodes are the same or not. This method is different from isequalNode(), where two different nodes can be equal but not the same, here the same node means that they are referencing the same object. Syntax: node.isSameNode(othernode) Parameters: The "othe
    1 min read
    HTML DOM console timeEnd() Method
    The console.timeEnd() method in HTML is used to end a timer started by the console.time() method. This can be used to calculate the time of certain operations for testing purposes. Syntax:console.timeEnd( label )Parameters: This method accepts single parameter label which is optional. It is used to
    3 min read
    HTML DOM getAttributeNode() Method
    The getAttributeNode() method in HTML DOM is used to return the attribute node with the specified name of an element, as an attribute object. This function is similar to the getAttribute() method but the only difference is that the getAttribute() method returns the value of an attribute node, not an
    2 min read
    HTML DOM scrollWidth Property
    The DOM scrollWidth property is used to return the width of an element. This property includes padding and also content that is not visible on the screen due to overflow but does not include a border, scrollbar, or margin. It is a read-only property. Syntax: element.scrollWidth Return Value: It retu
    1 min read
    HTML DOM cloneNode() Method
    The HTML DOM cloneNode() Method is used to copy or clone a node on which the cloneNode() method is called. For example, a list item can be copied from one list to another using this method.Syntax: yourNode.cloneNode([deep]) Parameters: The [deep] is an optional argument. We can set its value to "tru
    3 min read
    HTML onunload Event Attribute
    The onunload event attribute works when the document is being unloaded i.e. it occurs when the browser has been closed. It is mostly used when the user opens a link and submits the form and closes the browser window. Basically, it is: Fired when a user navigates away from a page or closes the browse
    1 min read
    HTML DOM exitFullscreen() Method
    The exitFullscreen() method requests the element which is currently in full-screen mode to be taken out of full-screen mode. If the element is not in full-screen mode, then nothing gets changed. The reverse of this method is requestFullscreen(). Syntax: HTMLElementObject.exitFullscreen() Parameters:
    1 min read
    HTML DOM children Property
    The DOM children property is used to return an HTML collection of all the child elements of the specified element. The elements in the collection can be accessed by index numbers. It differs from childNodes as childNodes contain all nodes (i.e. it includes text and comment nodes as well) but on the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences