Element

Element.prototype.appendChild

Adds a node to the end of the list of children of a specified parent node

Syntax

JavaScript
element.appendChild(child)

Parameters

ParameterTypeDescription
childNodeThe node to append to the given parent node

Return Value

The appended child Node

Examples

Basic Usage
const list = document.querySelector('ul')
const item = document.createElement('li')
item.textContent = 'New item'
list?.appendChild(item)
Practical Example
const container = document.getElementById('output')!
const p = document.createElement('p')
p.textContent = 'Added dynamically'
container.appendChild(p)
Advanced Usage
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

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.