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 introduced
Copy 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 Method
Copy 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 class
Copy codeThe Code is as follows:
Function addClass (element, value ){
If (! Element. className ){
Element. className = value;
} Else {
NewClassName = element. className;
Element. className = newClassName + "" + value;
}
}