Element.prototype.appendChild
Adds a node to the end of the list of children of a specified parent node
Syntax
element.appendChild(child)Parameters
| Parameter | Type | Description |
|---|---|---|
| child | Node | The node to append to the given parent node |
Return Value
The appended child Node
Examples
const list = document.querySelector('ul')
const item = document.createElement('li')
item.textContent = 'New item'
list?.appendChild(item)const container = document.getElementById('output')!
const p = document.createElement('p')
p.textContent = 'Added dynamically'
container.appendChild(p)function addOption(select: HTMLSelectElement, value: string, text: string) {
const option = document.createElement('option')
option.value = value
option.textContent = text
select.appendChild(option)
}Understanding Element.prototype.appendChild
The Element.prototype.appendChild method in JavaScript adds a node to the end of the list of children of a specified parent node. It belongs to the Element object and is one of the most widely used methods for working with element values in modern JavaScript and TypeScript applications.
The method signature is element.appendChild(child). It accepts 1 parameter: child. When called, it returns the appended child node. Understanding when and how to use appendChild() helps you write more expressive, readable code.
Common use cases for Element.prototype.appendChild include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like dom-append, dom-prepend, dom-insertbefore, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Element.prototype.appendChild is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Element.prototype.appendInserts a set of Node objects or strings after the last child of the Element
Element.prototype.prependInserts a set of Node objects or strings before the first child of the Element
Element.prototype.insertBeforeInserts a node before a reference node as a child of a specified parent node
Element.prototype.removeChildRemoves a child node from the DOM and returns the removed node
More Element Methods
Other methods in the Element object
Related Tools
More Element Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.