
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM lastChild Property
The HTML DOM lastChild property is used to access and retrieve the last child node of a specified parent element within the HTML DOM.
This property is useful for manipulating the DOM, as it allows developers to easily identify and interact with the last child, whether it is an element node, text node, or comment.
If the parent element has no children, lastChild will return null.
Syntax
Following is the syntax of HTML DOM lastChild property −
element.lastChild;
Parameters
Since it is a property, it does not accept any parameters.
Return Value
This property returns a node that points to the last child node of a specific parent element. If no last child exists, it returns 'null'.
Example 1: Accessing the lastChild of Div Element
The following is the basic example of the HTML DOM lastChild property. It retrieved the last child of a Last paragraph Click the below button to get the last child of div element. The above program returns the last child of a "div" element. Following is another example of the HTML DOM lastChild element. We use this property to access the last child of the This example shows how to dynamically modify the content of the last child of a First paragraph Last paragraph The example below shows the dynamic insertion of a new last child element into a list of items upon clicking a button using the lastChild property − Inserting a new Last Child dynamically.. First paragraph Last paragraph with some whitespace before closing tag
Example 2: Last Child Node of an "ul" Element
element −
Below are List of ul items :
Example 3: Modifying Last Child Content of Div Element
This is the div content with their child nodes:
Modified last child node:
Example 4: Inserting Last Child Dynamically
Span element
Supported Browsers
Property
lastChild
Yes
Yes
Yes
Yes
Yes