tags:

views:

20

answers:

3

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

+1  A: 

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!

Squirkle
+2  A: 

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
GenericTypeTea
A: 

you can use .style of the DOM element

document.getElementById("id").style.left
Haim Evgi