JavaScript Tutorial/DOM Node/createElement

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

Create an element from document

   <source lang="javascript">

<html> <head> <title>appendChild() Example</title> <script type="text/javascript">

  function appendMessage() {
     var oNewP = document.createElement("p");
     var oText = document.createTextNode("www.wbex.ru");
     oNewP.appendChild(oText);
     document.body.appendChild(oNewP);
  }

</script> </head> <body onload="appendMessage()">

Hello World!

</body> </html></source>


Create Paragraph element and set the text

   <source lang="javascript">

<html> <head> <title>appendChild() Example</title> <script type="text/javascript">

  function appendMessage() {
     var oNewP = document.createElement("p");
     var oText = document.createTextNode("www.wbex.ru");
     oNewP.appendChild(oText);
     document.body.appendChild(oNewP);
  }

</script> </head> <body onload="appendMessage()">

Hello World!

</body> </html></source>