Can I use the following code to compare the value of the attribute "left" ?
if ($('.pager').css('left') < 100 + 'px')
Or should I different code ? (My 开发者_如何转开发issue is how to deal with 'px', if I should remove it or at least use it consistently in the code.
thanks
Just use parseInt
, it will ignore the px
for you:
if (parseInt($('.pager').css('left')) < 100)
Or you can use the left
property within position()
:
var left = $('.pager').position().left;
if (left < 100) // Etc
Consider using a variable.
var pagerPos = parseInt($('.pager').css('left'))
if (pagerPos < 100) {...}
Remember that your if statement is in this case trying to compare a number value to a number value. You need to use parseInt() to strip off the 'px' held in the CSS. After that you should be golden!
you can use .style
of the DOM element
document.getElementById("id").style.left
精彩评论