Moses wrote on 19 mrt 2007 in comp.lang.javascript
:
I need to check weather a node has next sibling so I tried
if(node.nextSibling == null) it works for IE but for FF it always
return true, because FF takes white space as a node. So I have
rewritten the function.
Good detective work!
function hasNextSibling(node)
{
var node =node.nextSibling;
if(node==null){//For IE
return (false);
No need for the parentheses
}
else{//For FF
no need for else, if the first if-effect exits the function
while (node.nodeType!=1){
node=node.nextSibling;
if(node == null)
break;
}
===============
This part:
if (node == null){
return (false);
}
else{
return (true);
}
[No need for the parentheses around true and false]
.... is the same as:
return node != null;
}
}
So the whole function can be written as:
function hasRealNextSibling(node) {
var node = node.nextSibling;
if (node == null) return false; //For IE
while (node.nodeType != 1){
node = node.nextSibling;
if (node == null) break;
};
return node != null;
};
[However, I believe that an empty <spanis not detected right.]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)