<p id="p" name="kang">内容</p>
<html> <head> <title>标题</title> </head> <body> <h1>题目</h1> <p>内容</p> </body> </html>
<p id="xiu">文本</p> <script> docuemt.getElementById("xiu"); </script>
<p>文本</p> <script> document.getElementsByTagName("p"); </script>
<p class="xiu">文本</p> <script> document.getElementsByClassName("xiu"); </script>
<span> <p id="xiu">文章</p> </span> <script> document.getElementById("xiu").parentNode; </script>
<div id="xiu"> <p></p> </div> <script> document.getElementById("xiu").childNodes; </script>
<div id="xiu"> <p></p> </div> <script> document.getElementById("xiu").firstChild; </script>
<p id="xiu">修抗</p> <script> document.getElementById("xiu").style.color = "red"; </script>
<script> var classNode = document.createAttribute("class"); classNode.value = "xiu";</script>
<div id="app"></div> <script> var classNode = document.createAttribute("class"); classNode.value = "xiu"; var appNode = document.getElementById("app"); appNode.setAttributeNode(classNode); </script>
<script>
document.createTextNode("内容");
</script>
<script> document.createElement("p");</script>
- appendChild()插入元素节点/文本节点
<div id="app"></div> <script> var pNode = document.createElement("p"); var appNode = document.getElementById("app"); appNode.appendChild(pNode); </script>
<div id="app"></div> <button onclick="xiu()">按钮</button> <script> function xiu(){ var pNode = document.createElement("p"); var txtNode = document.createTextNode("文本"); pNode.appendChild(txtNode); var appNode = document.getElementById("app"); appNode.insertBefore(pNode,appNode.childNodes[0]); } </script>
<div id="xiu"> <p>1</p> <p>2</p> <p>3</p> <p>4</p> </div> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var list=document.getElementById("xiu"); list.removeChild(list.childNodes[0]); } </script>
··END··