1<html>
2<head>
3<title>t1</title>
4<script type="text/javascript">
5 function addNode()
6 {var newP = document.createElement("p");
7 var textNode = document.createTextNode(" This is a new text node");
8 newP.appendChild(textNode);
9 document.getElementById("firstP").appendChild(newP); }
10</script> </head>
11<body> <p id="firstP">firstP<p> </body>
12</html>
13
1//create and append element
2 var node = document.createElement("LI"); // Create a <li> node
3
4 var textnode = document.createTextNode("Water"); // Create a text node
5
6 node.appendChild(textnode); // Append the text to <li>
7
8 document.getElementById("myList").appendChild(node);
1var newTH = document.createElement('th');
2newTH.innerHTML = 'Hello, World!';
3newTH.onclick = function () {
4 this.parentElement.removeChild(this);
5};
6
7var table = document.getElementById('content');
8table.appendChild(newTH);
9