parseInt % and px problem
Asked Answered
C

2

6
<div style="left: 100%"></div>

parseInt($("div").css("left"), 10);

When I try to get value of left, some browsers give result in pixels, some in %.

Here is an example http://jsfiddle.net/WTt4s/1/

Google Chrome gives percent value, IE9 gives pixels instead.

How do I get the same value in all browsers (px or %)?

Coroneted answered 9/5, 2011 at 14:26 Comment(6)
have you checked the actual text value of top? Is it still in percent or have the browsers converted it to pixels? If it is still in percent, what happens if you strip the '%' character before doing the parseInt? -- $("div").css("top").replace('%','')Atmosphere
What's the output of alert($("div").css("top")) in place of the parseInt?Geoid
it does not seem like a parseInt problem but browser related behaviorImprimatur
Please provide a test case, preferably using jsFiddle.Cola
@Atmosphere you are true, browser convers value to pixels. I get 100px instead of 100% without parseInt.Coroneted
added a test case on jsfiddleCoroneted
D
4

Try this one parseInt($("div")[0].style.top, 10)

Discovery answered 9/5, 2011 at 14:32 Comment(0)
C
0

Try to use .offset().top or .position().top instead

Catamount answered 9/5, 2011 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.