Insert element before another element by using document.body.insertBefore : Insert : DOM Node JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » DOM Node » Insert »

 

Insert element before another element by using document.body.insertBefore

















<html>
    <head>
        <title>insertBefore() Example</title>
        <script type="text/javascript">
            function insertMessage() {
                var oNewP = document.createElement("p");
                var oText = document.createTextNode("www.navioo.com");
                oNewP.appendChild(oText);

                var beforeMe = document.getElementsByTagName("p")[0];
                document.body.insertBefore(oNewP, beforeMe);
            }
        </script>
    </head>
    <body onload="insertMessage()">
        <P>Hello World!</p>
    </body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo DOM Node
» Insert