JavaScript: Create and Insert HTML Element

By Xah Lee. Date: . Last updated: .

This page shows you how to use JavaScript to create an HTML element and insert it into a page.

Press the following button to see a paragraph element inserted.

Here is the HTML code:

<button id="button69908" type="button">Click Me</button>

Here is the JavaScript code:

const button69908 = document.getElementById("button69908");

const ff = (() => {
 const newNode = document.createElement("p");
 button69908. insertAdjacentElement("afterend", newNode);

button69908 . addEventListener ("click", ff , false);
JavaScript in Depth

DOM Common Examples

DOM Scripting


DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc