JavaScript Tutorial/DOM Node/Insert

Материал из Web эксперт
Версия от 11:24, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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

   <source lang="javascript">

<html>

   <head>
       <title>insertBefore() Example</title>
       <script type="text/javascript">
           function insertMessage() {
               var oNewP = document.createElement("p");
               var oText = document.createTextNode("www.wbex.ru");
               oNewP.appendChild(oText);
               var beforeMe = document.getElementsByTagName("p")[0];
               document.body.insertBefore(oNewP, beforeMe);
           }
       </script>
   </head>
   <body onload="insertMessage()">

Hello World!

   </body>

</html></source>