javascript insertafter code example
Example 1: insert element after element javascript
function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
Example 2: insert element after element javascript
//insert new Element after some reference Element
function insertAfter(newElement, referenceElement) {
referenceElement.parentNode.insertBefore(newElement, referenceElement.nextSibling);
}
//example usage
var newElement = document.createElement("div");
newElement.innerHTML = "my New Div Text";
var myCurrentElement= document.getElementById("myElementID");
insertAfter(newElement, myCurrentElement);
Example 3: insertafter js
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}