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

Benoit has posted 48 posts at DZone. View Full User Profile

InsertAfter() With InsertBefore() And Node.nextSibling

02.26.2008
| 19538 views |
  • submit to reddit
        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>