I have a curious problem with some javascript. In the following code the browser will execute more than one path in the if, else if, else if conditions. So for example the console will log “a c” or “b c”.
if (divs[i].row == hover_div.row && divs[i].obj != hover_div.obj)
{
console.log("a");
divs[i].obj.stop()
.animate({'width':d_thin}, { duration:600, queue:false })
.animate({'height':d_expand}, { duration:600, queue:false });
}
else if (divs[i].col == hover_div.col && divs[i].obj != hover_div.obj)
{
console.log("b");
divs[i].obj.stop()
.animate({'width':d_expand}, { duration:600, queue:false })
.animate({'height':d_thin}, { duration:600, queue:false });
}
else if (divs[i].obj != hover_div.obj);
{
console.log("c");
divs[i].obj.stop()
.animate({'width':d_thin}, { duration:600, queue:false })
.animate({'height':d_thin}, { duration:600, queue:false });
}
I’ve checked that the code isn’t executing twice by adding a counter just outside the block. If I nest the if statements as below the whole thing works fine, but I shouldn’t need to should I?
if (divs[i].row == hover_div.row && divs[i].obj != hover_div.obj)
{
console.log("a");
divs[i].obj.stop()
.animate({'width':d_thin}, { duration:600, queue:false })
.animate({'height':d_expand}, { duration:600, queue:false });
}
else {
if (divs[i].col == hover_div.col && divs[i].obj != hover_div.obj)
{
console.log("b");
divs[i].obj.stop()
.animate({'width':d_expand}, { duration:600, queue:false })
.animate({'height':d_thin}, { duration:600, queue:false });
}
else {
if (divs[i].obj != hover_div.obj);
{
console.log("c");
divs[i].obj.stop()
.animate({'width':d_thin}, { duration:600, queue:false })
.animate({'height':d_thin}, { duration:600, queue:false });
}
}
}
delete the semicolon