joe joe - 1 year ago 77
Javascript Question

jQuery/Javascript if css right > go to this css value

Can anyone tell me why the conditional in my code is never true?


It's because I was checking a string against a number and needed to use


Answer Source

You need to parseInt():

$('.zeppelin').css('right') > winWidth

$('.zeppelin').css('right') will return [integer]px. Therefore you are comparing a string type to an integer type.


parseInt($('.zeppelin').css('right')) > winWidth

Also, as a side note, looking through your code, you have:


If you wish to invert an integer, multiply it by -1 instead:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download