1. Obtain the next element of the current element.
Copy codeThe Code is as follows: function getNextElement (node ){
If (node. nodeType = 1 ){
Return node;
}
If (node. nextSibling ){
Return getNextElement (node. nextSibling );
}
Return null;
};
2. Add the page loading method for js externally introducedCopy codeThe Code is as follows: function addLoadEvent (func ){
Var oldonload = window. onload;
If (typeof window. onload! = 'Function '){
Window. onload = func;
} Else {
Window. onload = function (){
Oldonload ();
Func ();
}
}
};
3. insertAfter MethodCopy codeThe Code is as follows: function insertAfter (newElement, targetElement ){
Var parent = targetElement. parentNode;
If (parent. lastChild = targetElement ){
Parent. appendChild (newElement );
} Else {
Parent. insertBefore (newElement, targetElement. nextSibling );
}
};
4. Add a classCopy codeThe Code is as follows: function addClass (element, value ){
If (! Element. className ){
Element. className = value;
} Else {
NewClassName = element. className;
Element. className = newClassName + "" + value;
}
}