This example describes the definition and usage of JavaScript insertafter (). Share to everyone for your reference, specific as follows:
HTML section:
<div id= "B" >bbbbbbbbb</div>
<div>dddddd</div>
JavaScript section:
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. Which is the back of the target element.
}
}
For more information on JavaScript-related content readers can view the site topics: "JavaScript common function Tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"
I hope this article will help you with JavaScript programming.