I have in my html document several div elements with certain css class and want to get x, y position of those elements, thanks in advance.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
getBoundingClientRect:http://ejohn.org/blog/getboundingclientrect-is-awesome/
For example:
Remember that
getBoundingClientRectgives the coordinates relative to the current viewport, which means that if you want to know the coordinates relative to thedocument.body, you have to add the horizontal and vertical scroll amounts (document.documentElement.scrollLeftordocument.body.scrollLeftfor Firefox, and.scrollTopof course).