If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Finding X, Y of div

Hello.

I have a div, which can be anywhere in the document. I want it like, when I click anywhere on the div, it tells me the X, Y of the mouse in the div. Like X mouse - X div (left) and Y mouse - Y div (bottom). So that I know the width and height of the mouse according to the div. Is it possible or cross browser?

This thing works for a textarea. But when I use an 'img' for 'div' instead of that:
e.layerY || e.offsetY will give the height from all the element above this. for example by clicking the top border of the image, instead of giving me the low number (like 0), it gives me 300, or 500 depends on the height of other elements above the image.

This thing works for a textarea. But when I use an 'img' for 'div' instead of that:
e.layerY || e.offsetY will give the height from all the element above this. for example by clicking the top border of the image, instead of giving me the low number (like 0), it gives me 300, or 500 depends on the height of other elements above the image.

Is there a workaround for this?

that's what i was afraid of. if something's too good to be true, it usually is.
i'm afraid you will have to calculate the entire sequences of offsets on the wrapping tags, and subtract that from your event property coords.

here is an example of finding the total left offset, from which subtracting the coords you already have should give you an element-relative coord:

I want to be able to click on a 'div', and be able to change its background image position.
For example I click on X:20,Y:100 on it (20 and 100 relating to the div) and it set background image position (background-position) to '20px 100px'.