- From: Joao Eiras <joao.eiras@gmail.com>
- Date: Mon, 04 Sep 2006 23:32:59 +0100
- To: www-dom@w3.org
At http://www.w3.org/DOM/L2CR2comments_public.html
Issue Core-13:
Why not Node.insertAfter()
Resolution:
node.insertAfter(newKid,refChild), if it existed, would be precisely
equivalent to node.
insertBefore(newKid,refChild.getNextSibling()).So insertAfter might be
convenient, but isn't strictly necessary.
This isn't quite correct. There can be no nextSibling.
A implementation of insertAfter (in javascript) would be
Node.prototype.insertAfter = function (newChild, refChild) {
if (refChild.nextSibling)
this.insertBefore(newChild, refChild.nextSibling);
else if (refChild.parentNode == this)
this.appendChild(newChild);
else
throw "NOT_FOUND_ERR";//whatever - refChild isn't child of current
node
}
Since this piece of code is extremely simple, and trivial, there's no
reason for it not to become part of the DOM core. It's easier than having
to carry it always around.
Received on Monday, 4 September 2006 22:33:28 UTC