For accurate results, please disable Firebug before running the tests. Featured on Meta By using our site, you acknowledge that you have read and understand our jQueryで要素の位置を取得したり移動させるには offset() を使います。位置がズレたり、undefinedエラーになる場合の対処法もご紹介します。 For complete documentation and demo see: Here's one way to position your elements using the position feature:Here is an option. The Overflow Blog This tutorial show how to use jQuery methods to get or set dimensions of DOM elements. Stack Overflow works best with JavaScript enabled It seems to work just fine for me and It is essentially the same as the unchosen answer below that has 85+ votes. @Xan: Yeah, I'm surprised that nether Chrome nor jQuery had any means of determining page zoom. Otherwise it is not hard to find your error. Thanks!Maybe that's because you use jQuery UI while the OP asks only jQuery.often people go tooooo far with the down voting. How to get and set the position of an element with the jQuery I recommend another option.

For some reason those methods return the same values as if no zooming was done.Do I need to use other functions to account for the page zoom?Thanks for contributing an answer to Stack Overflow! Stack Overflow for Teams is a private, secure spot for you and

Stack Overflow for Teams is a private, secure spot for you and By clicking “Post Your Answer”, you agree to our To subscribe to this RSS feed, copy and paste this URL into your RSS reader. What I am trying to do is get the coordinates of where an element was clicked relative to the top-left of the element. Free 30 Day Trial Lets not assume that a wider answer is useless to others even if it may be an expansion of the OP. I'm testing the following for the latest Chrome browser only (need it for my Chrome Extension. I was relying on jQuery to get me offsets of DOM elements and their height using the offset(), outerHeight() and other methods.. Please do tell why, if you down vote my answer. Java applet disabled. how can I set to bottom and right of div? )I was relying on jQuery to get me offsets of DOM elements and their height using the This works fine except when the tab/page is zoomed up or down. site design / logo © 2020 Stack Exchange Inc; user contributions licensed under Also in: Traversing > Tree Traversal your coworkers to find and share information. Warning! The jQuery library includes various methods to manipulate DOM element's dimensions like height, width, offset… I'm testing the following for the latest Chrome browser only (need it for my Chrome Extension.) there's no bottom,right property in offsetThis answer was voted down twice, with no explanation. By clicking “Post Your Answer”, you agree to our To subscribe to this RSS feed, copy and paste this URL into your RSS reader. .offset() Get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.

The Overflow Blog I guess you are assigning the values to a global variable.There are methods coming to extension APIs to get zoom information, but the milestone is Chrome 38. This works fine except when the tab/page is zoomed up or down. See the link above or try offset().left and css.left are not same thing, they may or may not have the same values depending on the page structure.I +1'd. Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunitiesInclude all the code you are using. Let's say I have a div layer1 and another layer2. What worked for me though was to get zoom using this method/hack and then multiply/divide the results returned by jQuery functions: Problem is that jQuery.offset().top is actually giving me a decimal value in FFX 3.6 (in IE and Chrome, the two values match). your coworkers to find and share information. jQuery.offset() is supposed to provide an abstraction for this to provide the correct value xbrowser. site design / logo © 2020 Stack Exchange Inc; user contributions licensed under By using our site, you acknowledge that you have read and understand our jQuery still does not have a setter on @Koshinae It's part of jQuery "UI". This is just for the x coordinates.Thanks for contributing an answer to Stack Overflow! Free 30 Day Trial Don't get me started on the 'closed as this is not a proper question' ;)@KSev - I'm from the future. The .position() method allows us to retrieve the current position of an element (specifically its margin box) relative to the offset parent (specifically its padding box, which excludes margins and borders). Stack Overflow works best with JavaScript enabled Test runner. Also, why don't you accept Steve's answer below?!hey! jQuery UI has a new position feature that allows you to position elements relative to each other. Featured on Meta How to get and set the position of an element with the jQuery .offset method?

Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunitiesDenise, did you even check the .offset() method on jQuery website?