$(document).ready(function(){ $('.run').click(function(){ var $mgTop = $('.itmFirst').css('margin-top'); if($mgTop<'100px'){ $('.itmFirst').animate({marginTop:'+=30px'},1000,function(){}); }; }); 
  • $mgTop<'100px' replace with $mgTop<100 - Visman
  • And here marginTop:'+=30px' maybe not everything is right with the summation of the line. - Visman Sep.
  • @Visman doesn't work like that even for the first time, and from marginTop:'+=30px' is essentially all right. - Alexander

1 answer 1

Work example http://jsfiddle.net/szpayf30/

 $('.run').click(function(){ var mgTop = $('.itmFirst').css('margin-top').replace("px", ""); if(mgTop<100){ $('.itmFirst').animate({marginTop:'+=30px'},1000,function(){}); }; }); 

From the property string, remove the px substring so that only a number is left in the string. And further in the condition to compare with the number, and not with the string.

  • thanks, now it works :) - Alexander