Saturday, January 17, 2026
HomeLanguagesJavascriptHTML DOM ParentNode.append() Method

HTML DOM ParentNode.append() Method

The ParentNode.append() method is used to insert Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as Text nodes.

Syntax:

ParentNode.append( ChildNodesToPrepend );

Parameters: This parameter holds the set of Node or DOMString objects that is to be inserted as the last child of parent element.

Below examples illustrate the ParentNode.append() method:

Example 1: In this example, we will append an element. To show this method, we have created three elements parentNode, Child1 and Child2. Then we have appended the Child1 and Child2 to parentNode.

In console, we had shown childNodes of parentNode.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
</head>
  
<body>
    <h1>neveropen</h1>
  
    <script>
        var parentNode = document.createElement("div");
        var Child1 = document.createElement("p");
        var Child2 = document.createElement("div");
        parentNode.append(Child1);
        parentNode.append(Child2);
        console.log(parentNode.childNodes); 
    </script>
</body>
  
</html>


Output:

In console, you can see childNodeList of parentNode. One is p and one is div.

Example 2: In this example, we have appended some text to innerHTML of the element and the element’s textContent.

HTML




<!DOCTYPE html>
<html lang="en">
  
<body>
    <h1>neveropen</h1>
  
    <script>
        var parent = document.createElement("div");
        parent.innerHTML = "neveropen : ";
        parent.append("A Computer Science Portal for Geeks");
        console.log(parent.textContent); 
    </script>
</body>
  
</html>


Output:

In console, you can see textContent of parent element.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Apple Safari
  • Opera
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS