Append some desired effects or attributes to the end of the specified element. You may have encountered this problem. Next, I will introduce the append implementation code in detail, if you are interested, refer
The Code is as follows:
Var header1 = document. getElementById ("header ");
Var p = document. createElement ("p"); // create an element node
InsertAfter (p, header1); // create a method by yourself because js does not directly append the method to the end of the specified element.
Function insertAfter (newElement, targetElement) {// newElement is the element to be appended. targetElement is the position of the specified element.
Var parent = targetElement. parentNode; // locate the parent node of the specified Element
If (parent. lastChild = targetElement) {// determine whether the specified element is the last position in the node. if yes, use the appendChild method directly.
Parent. appendChild (newElement, targetElement );
} Else {
Parent. insertBefore (newElement, targetElement. nextSibling );
};
};