Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript HTML DOM</h2> <p>Add a new HTML Element.</p> <div id="div1"> <p id="p1">This is a paragraph.</p> <p id="p2">This is another paragraph.</p> </div> <script> const para = document.createElement("p"); const node = document.createTextNode("This is new."); para.appendChild(node); const element = document.getElementById("div1"); const child = document.getElementById("p1"); element.insertBefore(para,child); </script> </body> </html>