There is no need to write an insertAfter function.
Originally Posted by mnaseersj
Why? The nextSibling property returns null if there is no next sibling.
When the insertBefore has null as the referenc element, it automatically appends instead.
For confirmation, this is what the insertBefore documentation page has to say:
var insertedElement = parentElement.insertBefore(newElement, referenceElement);
If referenceElement is null, newElement is inserted at the end of the list of child nodes.
So, the following is the only code that you need to properly insert after an element, regardless of whether that element has any siblings after it or not.