js add sibling after code example
Example 1: javscript insert element after another
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: javascript insert sibling after
<!-- beforebegin -->
<p>
<!-- afterbegin -->
foo
<!-- beforeend -->
</p>
<!-- afterend -->
var tempDiv = document.createElement('div');
paragraph.insertAdjacentElement('afterend', tempDiv);
<p>
foo
</p>
<div></div>
Example 3: append sibling javascript after first child
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}