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

How to appendChild(element) many times. (The same element)

appendChild will remove the node from wherever it is before appending it to its new location, so you need to make copies of the node instead. You can use cloneNode for that. The true makes cloneNode perform a deep clone, i.e. with all its child nodes. for(var i = 0; i < urls.length; i++){ sliderBody.appendChild(slide.cloneNode(true)); … Read more

tech