JQuery: using css selector to compare position values?

Can the following code be used to compare the value of the "left" attribute?

if ($('.pager').css('left') < 100 + 'px')

Or do I need another code? (My problem is how to deal with 'px' if I have to remove it or at least use it consistently in code.

thank

+3
source share
3 answers

Just use it parseInt, it will ignore pxfor you:

if (parseInt($('.pager').css('left')) < 100)

Or you can use the property leftin position():

var left = $('.pager').position().left;
if (left < 100) // Etc
+6
source

Consider using a variable.

var pagerPos = parseInt($('.pager').css('left'))
if (pagerPos < 100) {...}

, if . parseInt(), "px", CSS. !

+1

.style DOM

document.getElementById("id").style.left
0
source

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


All Articles