The example in this article describes how JavaScript uses appendchild to append nodes. Share to everyone for your reference. The specific analysis is as follows:
The increase in the DOM tree node, the instance code is as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
function T () {
var nodep = document.createelement (' P ');//Create P node
var art = document.createTextNode (' Hello, world '); Create a text node
var cont = document.getElementById (' container ');//Get node
Cont.appendchild (NODEP)//Add node
Nodep.appendchild (art);//Add text node
}
</script>
<style type= "Text/css" >
P{width:100px;height:100px;background:green;}
#container P{width:100px;height:100px;background:blue;}
</style>
<body>
<div id= "Container" ><p>hello world</p>
</div>
<p> say a few words </p>
<button onclick= "t ()" value= "" > Add node </button>
</body>
I hope this article will help you with your JavaScript programming.