标签:
function insertAfter(newElement,targetElement){
var parent=targetElement.parentNode;
if(parent.lastChild==targetElement){
parent.appendChild(newElement);
}else{
parent.insertBefore(newElement,targetElement.nextSibling);
}
}
注:newElement=document.getElementById("id");
targetElement为刚创建的节点。例:
var para=document.createElement("p");
var para.setAttribute("id","desription");(等价于var testdiv=document.getElementById("description");testdiv.appendChild(para);)
var text=document.createTextNode("Hello world");
para.appendChila(text);
newElement=para;
标签:
原文地址:http://www.cnblogs.com/pcd12321/p/4198229.html