joe joe - 16 days ago 5
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?

http://jsfiddle.net/eygLU/2/

Solved:

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

parseInt()

Answer

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.

Try:

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

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

'-'+zepWidth

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

(zepWidth*-1)
Comments