insertAfter JS 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: insert element after element javascript
function insertAfter(newNode, existingNode) {
existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
Example 3: insert element after element 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 4: insertafter js
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
Example 5: js append html in div after
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<yourElement>
<div id='<your element id here>'>
<!--Your Jquery will be rendered here-->
</div>
</yourElement>
$('#<your element id here>').html(data);