
- 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 appendChild() Method
The HTML DOM appendChild() method is used to add a new child node (element) as the last child node into the specified parent node.
This method returns the appended child node. If the node already exists in the document, it is first removed from its current parent before being appended to the new parent.
You can only append one child node at a time. To append multiple nodes, you need to call this method multiple times.
Syntax
Following is the syntax of the HTML DOM appendChild() method −
element.appendChild(newNode);
Parameters
This method accepts a single parameter as listed below −
Parameter | Description |
---|---|
newNode | It represents the new child node that will be added to the parent element. |
Return Value
This method returns the appended child node that has been added to the parent element. If an error occurs during the append operation, it returns 'null'.
Example 1: Nested Appends to Documents
The example below helps you to understand how nested appends work by adding a paragraph inside a New paragraph added to the inner div. Following is another example of HTML DOM appendChild() method, which shows how you can add paragraphs dynamically to a web page − Adding Paragraph dynamically click on button to see the added paragraph content... This example shows how you can create a simple list dynamically(runtime). When the "Add List" button is clicked, a new list (i.e., li element) gets added to the Unordered list (ul) − Creates a List click on the button to append more list items.... In the following example, we are using the appendChild() method to append an image dynamically into a web page − Inserts an Image Dynamically Clicking the button appends more images... This example shows how to add a text node to an existing HTML element using the HTML DOM appendChild() method − Appending Text Nodes
Before
Appended with new paragraph content
Example 2: Adding Paragraphs Dynamically
Example 3: Creating a Simple List
Example 4: Inserting Images Dynamically
Example 5: Adding Text Nodes
Before Appending Text Node:
After Appending Text Node:
Supported Browsers
Method
appendChild()
Yes
Yes
Yes
Yes
Yes