javascript - Creating Nodes - sample p - (p1,p2,..)

<!DOCTYPE html>
<html>
<body>

<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>

<script>
var para1 = document.createElement("p");
var node1 = document.createTextNode("This is new 1.");
para1.appendChild(node1);

var para2 = document.createElement("p");
var node2 = document.createTextNode("This is new 2.");
para2.appendChild(node2);


var element = document.getElementById("div1");

element.appendChild(para1);
element.appendChild(para2);

</script>

</body>
</html>

Yorumlar