This article describes the definition and usage of javascript insertAfter(). Share it for your reference, as follows:
HTML part:
<div id="b">bbbbbbbb</div><div>dddddd</div>
JavaScript part:
window.onload=function(){ var a =document.createElement("span"); var b =document.createTextNode("cssrain"); a.appendChild(b); var mubiao = document.getElementById("b"); insertAfter(a,mubiao); }function insertAfter(newElement,targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) {// If the last node is the target element, add it directly. Because the default is the last parent.appendChild(newElement); } else { parent.insertBefore(newElement,targetElement.nextSibling);//If not, insert in front of the next sibling node of the target element. That is, behind the target element. }}For more information about JavaScript related content, please check out the special topics of this site: "Summary of Common JavaScript Function Skills", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"
I hope this article will be helpful to everyone's JavaScript programming.