jQuery: Determine absolute position of an element from the top
Question by Guest | 2013-09-22 at 22:00
I have a DIV container and would like to determine the absolute positioning of this element measured from the upper side of the web site using jQuery. So almost the top position of the container.
Is this possible with jQuery?
Related Topics
jQuery: Does an Element exist?
Tip | 1 Comment
jQuery: Show and hide elements
Tutorial | 0 Comments
jQuery: Scroll up and down with and without JavaScript
Tip | 0 Comments
JavaScript and jQuery: Replace content of an element by using innerHTML
Tutorial | 0 Comments
jQuery: Count Elements, Images, Classes etc
Tip | 0 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
HTML5 Canvas: Beginner Tutorial Chapter 4 - Write Text on Canvas
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Yes, it is. You can simply use the method .offset() giving us the current position of an element relative to the document. Offset provides us with your desired top position with .offset().top and the position from the left with .offset().left.
In this small example, we set the variable "a" to the top position of the container with the ID "mydiv" and "b" to the left-position of the same container.
If you are using the method .position() instead, you can determine the position relative to the parent element.
2013-09-25 at 18:56