Javascript examples for DOM:Element insertBefore
Insert before an element
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from www .ja v a 2s .c om test() }); </script> </head> <body> <script type="text/javascript"> function test() { var newDiv = document.createElement("div"); newDiv.innerHTML = "<h1>blah blah</h1>"; document.body.insertBefore(newDiv, document.getElementById('DOMTester')); } </script> <input id="DOMTester" type="submit" onclick="test()"> </body> </html>