I need to make this parison:
if (x < siteA.style.left || x > siteA.style.left + land.width() ) {
however siteA.style.left returns 20px (e.g) so the condition doesn't work. How do I remove the px and transform it into an integer so I can work with it?
I tried alert(parseInt(siteA.style.left))
and it returned NaN however alert(siteA.style.left)
returned 30px, 60px etc.
I need to make this parison:
if (x < siteA.style.left || x > siteA.style.left + land.width() ) {
however siteA.style.left returns 20px (e.g) so the condition doesn't work. How do I remove the px and transform it into an integer so I can work with it?
I tried alert(parseInt(siteA.style.left))
and it returned NaN however alert(siteA.style.left)
returned 30px, 60px etc.
4 Answers
Reset to default 3Use parseInt
:
var leftPos = parseInt(siteA.style.left, 10);
where 10
is the base, good practice to always specify it.
Just use parseInt().
Have you tried this?
var left = parseInt(siteA.style.left.replace('px', ''), 10)
When using jQuery you can use $('#siteA').offset().left
which returns only the integer value.