A group of Functions found on Firefox's official website is equivalent to treewalker. With this function, you can easily implement all the functions of traversal API 2 in IE (nextelementsibling, previuselementsibling, firstelementchild, lastelementchild, children) these functions let you find the next sibling, previous sibling, first child, and last child of a given node (element ). what makes them unique is that they safely ignore whitespace nodes so you get the real node you're looking for each time.
CopyCode The Code is as follows: function is_all_ws (NOD) {return! (/[^ \ T \ n \ r]/. Test (nod. Data ));}
Function is_ignorable (NOD) {return (nod. nodetype = 8) | (nod. nodetype = 3) & is_all_ws (NOD ));}
Function node_before (SIB ){
While (SIB = SIB. previussibling )){
If (! Is_ignorable (SIB) return SIB;
}
Return NULL;
}
Function node_after (SIB ){
While (SIB = SIB. nextsibling )){
If (! Is_ignorable (SIB) return SIB;
}
Return NULL;
}
Function first_child (PAR ){
VaR res = par. firstchild;
While (RES ){
If (! Is_ignorable (RES) return res;
Res = res. nextsibling;
}
Return NULL;
}
Function last_child (PAR ){
VaR res = par. lastchild;
While (RES ){
If (! Is_ignorable (RES) return res;
Res = res. previussibling;
}
Return NULL;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service