Answers for "js add sibling after"

6

javscript insert element after another

//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);
Posted by: Guest on July-31-2019
1

javascript insert sibling after

<!-- beforebegin -->
<p>
  <!-- afterbegin -->
  foo
  <!-- beforeend -->
</p>
<!-- afterend -->

var tempDiv = document.createElement('div');
paragraph.insertAdjacentElement('afterend', tempDiv);

// inserted div after end of paragraph tag
<p>
	foo
</p>
<div></div>
Posted by: Guest on April-04-2021
0

append sibling javascript after first child

function insertAfter(newNode, referenceNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
Posted by: Guest on December-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language