MrAdam Posted November 3, 2006 Share Posted November 3, 2006 does anybody know how to return the positions of an image (ie. top, left), that hasn't been set to position:absolute ? - if it's even possible..for example: <script type="text/javascript">function retrnPos(obj) { alert(' .. image top and image left .. ');}</script><img src="..." onClick="retrnPos(this);" /> -Thanks Link to comment Share on other sites More sharing options...
jesh Posted November 3, 2006 Share Posted November 3, 2006 I use offsetLeft and offsetTop quite often. var img = document.getElementById("MyPic");var left = img.offsetLeft;var top = img.offsetTop; Link to comment Share on other sites More sharing options...
aspnetguy Posted November 3, 2006 Share Posted November 3, 2006 jesh: can that be applied to other elements too? like div? Link to comment Share on other sites More sharing options...
jesh Posted November 3, 2006 Share Posted November 3, 2006 jesh: can that be applied to other elements too? like div?Yeah, I use it all the time. It's part of the DOM. You can get the left and top positions (offsetLeft, offsetTop) as well as the height and width (offsetHeight, offsetWidth) for any element.Different browsers seem to return different numbers (no suprise there, right?), but they are internally consistent: obj1.offsetLeft - obj2.offsetLeft should return the same value in both Firefox and IE. Link to comment Share on other sites More sharing options...
aspnetguy Posted November 3, 2006 Share Posted November 3, 2006 great thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now