What is appendChild in JavaScript ? Last Updated : 29 Nov, 2024 Comments Improve Suggest changes Like Article Like Report The appendChild() method is used to append a child element at the last of the target node. HTML <!DOCTYPE html> <html lang="en"> <body> <div id="container"></div> <script> const paragraph = document.createElement("p"); paragraph.textContent = "This is a new paragraph element added using appendChild() method."; const container = document.getElementById("container"); container.appendChild(paragraph); </script> </body> </html> SyntaxparentNode.appendChild(element);Parameterselement: The new child node that will be appended to the selected element.Return ValueJavaScript appendChild() method does not return anything. HTML <!DOCTYPE html> <html lang="en"> <body> <div id="container"> <button onclick="myFunction()" style="background-color: green; color: #fff; cursor: pointer;"> Click to add content </button> </div> <script> const myFunction = () => { const paragraph = document.createElement('p'); paragraph.textContent = 'This is a new paragraph element added using appendChild() method.'; document.getElementById('container').appendChild(paragraph); } </script> </body> </html> Comment More infoAdvertise with us Next Article What is appendChild in JavaScript ? M mguru4c05q Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript- Append in Array These are the following ways to append an element to the JS array: 1. Using Array.push() MethodJavaScript array.push() Method is used to add one or more elements to the end of the array.JavaScriptlet a = [ 10, 20, 30, 40, 50 ]; a.push(90); console.log(a);Output[ 10, 20, 30, 40, 50, 90 ] 2. Using Spr 2 min read JavaScript Ellipsis JavaScript Ellipsis (also known as the spread/rest operator) is represented by three dots (...). It is used for various tasks, such as spreading elements of an array into individual values or collecting multiple values into an array or object. It simplifies data manipulation and function parameter h 3 min read What is the difference between children and childNodes in JavaScript? DOM childNodes Property: The childNodes property is a property of Node in Javascript and is used to return a Nodelist of child nodes. Nodelist items are objects, not strings and they can be accessed using index numbers. The first childNode starts at index 0. Syntax element.childNodes DOM children Pr 2 min read How to append HTML code to a div using JavaScript ? The ability to append HTML code to a <div> Using JavaScript helps enhance user experience by enabling dynamic content updates without reloading the page. This technique is widely usedâover 85% of modern websites implement JavaScript DOM manipulation to create smoother and more interactive web 6 min read How to Add an ID to Element in JavaScript ? In JavaScript, the ID is the unique identifier through which the elements can be identified and manipulated if required. We can add an ID to an element in JavaScript using various approaches that are explored in this article with practical demonstration. Below are the possible approaches: Table of C 2 min read JavaScript - Insert Element in an array In JavaScript elements can be inserted at the beginning, end, and at any specific index. JS provides several methods to perform the operations.At the Beginning This operation inserts an element at the start of the array. The unshift() method is commonly used, which mutates the original array and ret 2 min read How to Create a Link in JavaScript ? In JavaScript, a link typically refers to creating HTML hyperlinks (<a> tags) dynamically using JavaScript. You can link using a document.createElement('a'), setting attributes like href and textContent, and then appending it to the document with appendChild().Here are some common approaches t 4 min read What is the use of append() method in JQuery ? In this article, we are going to see how to use the append() method in jQuery. The append() method is used to insert new content inside an existing element. There are some other methods also that provide to insert new content inside an existing element and these are - prepend(), html(), text(), befo 2 min read Insert at the Beginning of an Array in JavaScript Following are different ways to add new elements at the beginning of an array1. Using the Array unshift() Method - Most Used:Adding new elements at the beginning of the existing array can be done by using the Array unshift() method. This method is similar to the push() method but it adds an element 2 min read How to Push an Array into Object in JavaScript? To push an array into the Object in JavaScript, we will be using the JavaScript Array push() method. First, ensure that the object contains a property to hold the array data. Then use the push function to add the new array in the object.Understanding the push() MethodThe array push() method adds one 2 min read Like