siblings
function siblings(node){
if(node.nodeType === 1){
node.flag = true;
var children = node.parentNode.childNodes,
length = children.length,
tempArray = [],
i = 0;
for(; i < length; i++){
if(!children[i].flag && children[i].nodeType === 1 && children[i].nodeName !== 'SCRIPT'){
tempArray.push(children[i]);
}
}
return tempArray.length ? tempArray : null;
}
else{
return null;
}
}
next和pre
function next(node){
var next = node.nextSibling;
if(next !== null && next.nodeType === 3){
return next.nextSibling;
}
return next;
}
function pre(node){
var pre = node.previousSibling;
if(pre !== null && pre.nodeType === 3){
return pre.previousSibling;
}
return pre;
}
nextAll和preAll
function nextAll(node){
var nextNode = next(node),
nodeArray = [];
while(nextNode != null){
nodeArray.push(nextNode);
nextNode = next(nextNode);
}
return nodeArray;
}
function preAll(node){
var preNode = pre(node),
nodeArray = [];
while(preNode != null){
nodeArray.push(preNode);
preNode = pre(preNode);
}
return nodeArray;
}