Home > Web Front-end > JS Tutorial > Read JavaScript DOM Programming Art Notes_javascript skills

Read JavaScript DOM Programming Art Notes_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:59:33
Original
1157 people have browsed it

1. Get the next element of the current element

Copy code The code is as follows:

function getNextElement( node){
if(node.nodeType==1){
return node;
}
if(node.nextSibling){
return getNextElement(node.nextSibling);
}
return null;
};

2. Externally introduced js, add page loading method
Copy code The 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 code The 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 class
Copy code The code is as follows:

function addClass(element,value){
if(!element.className){
element .className=value;
}else{
newClassName=element.className;
element.className=newClassName " " value;
}
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template