add element after an element javascript code example
Example 1: append after javascript
function insertAfter(newElement, referenceElement) {
referenceElement.parentNode.insertBefore(newElement, referenceElement.nextSibling);
}
var newElement = document.createElement("div");
newElement.innerHTML = "my New Div Text";
var myCurrentElement= document.getElementById("myElementID");
insertAfter(newElement, myCurrentElement);
Example 2: insert element after element javascript
function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}