Is jquery bigger / smaller than just the first number?

I have a drag and drop script where I drag div.slider, I track the "left" value for div.slider and lose it when it is more than 68, but the problem is that it disappears when it reaches 6, not 68 If I change the number to 85, then it will disappear by 8, not 85. Does anyone know why this is happening?

$(document).ready(function() {

  $(".slider").mousemove(function() {
   var rightStyleValue = $('div.slider').css('left');
   $('.display_value').html(rightStyleValue);

      if ($('.slider').css('left') > 68 + 'px') {
              $('.container').fadeOut(500);   
      }   

  });
});
+3
source share
1 answer

Strings are compared lexicographically . Instead, compare the numerical comparison by converting the pixel value to an integer:

if (parseInt($('.slider').css('left')) > 68) {
    // …
}
+8
source

Source: https://habr.com/ru/post/1725501/


All Articles