JavaScript node.appendChild() Method

You are Here:

JavaScript node.appendChild() Method

The node.appendChild() method adds a node to the end of the list of children of a specified parent node.

Note: If the given child is a reference to an existing node in the document, node.appendChild() moves it from its current position to the new position.

Appending node to Body

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var node = document.createElement("h2"); var textnode = document.createTextNode("I'm Heading"); node.appendChild(textnode); document.body.appendChild(node); </script> </body> </html>

Syntax

node.appendChild(node)

Parameter Values

ValueTypeExplanation
nodeRequiredThe node to append to the given parent node.

Appending node to Specific Element

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point">Hello world</p> <script> var x = document.getElementById("point"); var node = document.createElement("h2"); var textnode = document.createTextNode("I'm Heading"); node.appendChild(textnode); x.appendChild(node); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author