how to use ' > ' or ' < ' in if condition jquery with margin left?

31 Views Asked by At

ex :

 if ( $div.css('marginLeft') == '-2000px') {

 } ..... it is working but i want to check it like

 if ( $div.css('marginLeft') > '-2000px') {

 } ...... Not working
1

There are 1 best solutions below

3
RobertAKARobin On BEST ANSWER

The problem is that '-2000px' is a string, and not a number. You cannot use > and < on strings in this way.

Try parsing $div.css as an integer, and writing the pixels as an integer (without the ''):

if ( parseInt( $div.css('marginLeft') ) > -2000 ){