William Lekatompessy
William Lekatompessy

Reputation: 165

How to use javascript OR operator?

I've been breaking my head over this 'simple' javascript snippet:

$("#hitbox").mouseleave(function() {
  if($("#sub-wrapper-1").height() < 179 || $("#sub-wrapper-2").height() < 179 ) {     
    $("#hitbox").animate({ "height" : '0px' }, 800), 
  } else {
    $("#hitbox").stop();
  }
});

Could you guys nudge me in the right direction on how to use the OR operator in javascript? The above code doesn't throw any errors, but it seems as it runs the function as an AND operator.

Upvotes: 2

Views: 28531

Answers (2)

gordon
gordon

Reputation: 1182

I find sometimes JS operators (in this case your || or) don't compare whole clauses, only the next item starting the clause. you may want to try wrapping your clauses w/ parens like so:

if(($("#sub-wrapper-1").height() < 179) || ($("#sub-wrapper-2").height() < 179 ))

Upvotes: 2

Mauro
Mauro

Reputation: 2070

Your OR operator is right (in fact in your case is simple javascript!)

It seems you have an error here

$("#hitbox").animate({ "height" : '0px' },800),

fix it as

$("#hitbox").animate({ height : '0px' },800);

Upvotes: 5

Related Questions