Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  124] [ 4]  / answers: 1 / hits: 45438  / 15 Years ago, wed, may 6, 2009, 12:00:00

There was a thread on this in comp.lang.javascript recently where
victory was announced but no code was posted:



On an HTML page how do you find the lower left corner coordinates of an element (image or button, say)
reliably across browsers and page styles? The method advocated in Ajax in Action (copy I have) doesn't seem to work in IE under some circumstances. To make the problem easier, let's assume we can set the global document style to be traditional or transitional or whatever.



Please provide code or a pointer to code please (a complete function that works on all browsers) -- don't just say that's easy and blather about what traversing the DOM -- if I want to read that kind of thing I'll go back to comp.lang.javascript. Please scold me if this is a repeat and point me to the solution -- I did try to find it.


More From » html

 Answers
7

In my experience, the only sure-fire way to get stuff like this to work is using JQuery (don't be afraid, it's just an external script file you have to include). Then you can use a statement like



$('#element').position()


or



$('#element').offset()


to get the current coordinates, which works excellently across any and all browsers I've encountered so far.


[#99587] Friday, May 1, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kelleyamiahk

Total Points: 216
Total Questions: 113
Total Answers: 119

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;