Get an Element's Position Using JavaScript | kirupa.com


#1

by kirupa | 18 December 2012

While this may be hard to believe, especially if you are familiar with how layout in HTML works, elements are positioned in some sort of sensible manner. Those manners are many and often confusing to discuss here, but there is some logic behind the position of everything you see. With great certainty, all elements end up at a particular location.


This is a companion discussion topic for the original entry at http://www.kirupa.com/html5/get_element_position_using_javascript.htm

#2

Great post. Do you have any copyright policy for the use of this code?


#3

Not at all - do whatever you want with the code snippets and samples :stuck_out_tongue:

I’m only restrictive about the tutorial text & images not being reproduced on other places.


#4

Where do you find the time to write all these great tutorials?? Speaking for myself after spending a full day at work in front of a computer I find it hard to get back on the computer when I get home again. :smile:


#5

I actually find writing and recording videos to be very relaxing :stuck_out_tongue:


#6

Hi. Newbie here, but I’m hoping you can help. I d/l your JS function to find the x,y position of an element on the window. But I’m getting ‘undefined’ when I do an alert. However, the element I’m trying to locate is an SVG element in an SVG block. Is that a problem, and if so, how can work around it? Many thanks, and really great work here.