添加节点
<html>
<head></head>
<body>
<div id="a">
<div id="a1">1</div>
<div id="a2">2</div>
<ul id="u1">
<li id="l1">
<a href="">222</a>
</li>
</ul>
</div>
<script type="text/javascript">
var newNode=document.createElement("li");
newNode.setAttribute("id","a3");
var txtNode=document.createTextNode("3");
newNode.appendChild(txtNode);
var newNodeA=document.createElement("a");
var txtA=document.createTextNode("111111111");
newNodeA.appendChild(txtA);
newNode.appendChild(newNodeA);
document.getElementById("u1").insertBefore(newNode,document.getElementById("l1"));
alert(document.getElementById("u1").innerHTML)
</script>
</body>
</html>
删除节点
<html>
<head>
<script>
</script>
</head>
<body>
<p id="p1">welcome to <b>javascript</b> world !</p>
<script language="javascript" type="text/javascript">
var a=document.getElementById("p1");
b=a.lastChild;
a.removeChild(b);
</script>
</body>
</html>