Javascript Append Child AFTER Element

You can use: if (parentGuest.nextSibling) { parentGuest.parentNode.insertBefore(childGuest, parentGuest.nextSibling); } else { parentGuest.parentNode.appendChild(childGuest); } But as Pavel pointed out, the referenceElement can be null/undefined, and if so, insertBefore behaves just like appendChild. So the following is equivalent to the above: parentGuest.parentNode.insertBefore(childGuest, parentGuest.nextSibling);

What is better, appending new elements via DOM functions, or appending strings with HTML tags?

Some notes: Using innerHTML is faster in IE, but slower in chrome + firefox. Here’s one benchmark showing this with a constantly varying set of <div>s + <p>s; here’s a benchmark showing this for a constant, simple <table>. On the other hand, the DOM methods are the traditional standard — innerHTML is standardized in HTML5 … Read more