Create an element from document : createElement « DOM Node « JavaScript Tutorial






<html>
<head>
<title>appendChild() Example</title>
<script type="text/javascript">
   function appendMessage() {
      var oNewP = document.createElement("p");
      var oText = document.createTextNode("www.java2s.com");
      oNewP.appendChild(oText);
      document.body.appendChild(oNewP);
   }
</script>
</head>
<body onload="appendMessage()">
<P>Hello World!</p>
</body>
</html>








23.5.createElement
23.5.1.Create an element from document
23.5.2.Create Paragraph element and set the text