DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
InsertAfter() With InsertBefore() And Node.nextSibling
insertAfter() with insertBefore() and node.nextSibling
Node.prototype.insertAfter = function(newNode, refNode) {
if(refNode.nextSibling) {
return this.insertBefore(newNode, refNode.nextSibling);
} else {
return this.appendChild(newNode);
}
}
<a href="http://www.ab-d.fr/">Source: Benoit Asselin</a>





