function insertAfter(ele,html){ var new_ele = document.createElement("div"); new_ele.innerHTML = html; var parent = ele.parentNode || document.body; parent.insertBefore(new_ele.firstChild, ele.nextSibling); } var d = document.getElementById("test"); insertAfter(d,"<div>dddddddd</div>")
<div id="test">a <div>Item1</div> <div>Item2</div> <div>Item3</div> <div>Item4</div>b </div>
var d = document.getElementById("test"); d.childNodes;//... d.previousSibling;//null d.nextSibling;//null d.parentNode;//body d.firstChild;//a d.lastChild;//b d.lastChild.textContent;//b d.lastChild.previousSibling.innerHTML;//Item4 d.childElementCount;//4 d.lastElementChild;//<div>Item4</div> d.childNodes.length;//9 d.childNodes[0];//"a" d.childNodes[1];//<div>Item1</div> d.childNodes[2];//""