Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> <style> #divId { color: green; font-size: 25px; } span { color: blue; font-size: 20px; } </style> </head> <body> <div id="divId">Welcome to W3docs</div> <script> function insertAfter(referenceNode, newNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } let elem = document.createElement("span"); elem.innerHTML = "It's a Javascript book"; let div = document.getElementById("divId"); insertAfter(div, elem); </script> </body> </html>