parent.prepend() 在元素前面添加元素
parent.append() 在元素后面添加元素
Code:
<body><ul id="app"><li>html</li></ul><script>var app =document.getElementById("app");var p = "<h1>hello world</h1>";var q ="wow I'm last"app.prepend(p);app.append(q);</script></body>
child.before(); 在元素前面添加元素
child.after(); 在元素后面添加元素
Code:
<body><p id="p">hello world</p><script>var p = document.getElementById("p");p.before("before");p.after("after");</script></body>
