1.appendChild()向节点的子节点列表的末尾添加新的子节点(增)

(1)appendChild()

(2)createElement(标签名):创建新的标签

(3)createTextNode(文本内容):创建文本节点

  1. <div id="app"></div>
  2. <script>
  3. var app=document.getElementById("app");
  4. var p=document.createElement("p"); //创建新的标签
  5. var txt=document.createTextNode("hello world"); //createTextNode() 可创建文本节点
  6. p.appendChild(txt); //将文本内容放到标签内
  7. app.appendChild(p); //在div标签中插入p标签
  8. </script>