1 function insert(){ 2 var tarDiv = document.getElementById("aId"); 3 var newDiv = document.createElement("div"); 4 newDiv.innerHTML = "insert"; 5 newDiv.id = "insert"; 6 oInsert.insertAfter(newDiv, tarDiv); 7 } 8 9 var oInsert = {10 insertAfter: function(newEl, targetEl){11 var parent = targetEl.parentNode;12 if(parent.lastChild == targetEl){13 parent.appendChild(newEl, targetEl);14 }else{15 parent.insertBefore(newEl, targetEl.nextSibling);16 } 17 }18 19 }