Show mouse position in DIV

I have set an onmousemove event on a DIV in which I want to locate
the position of the mouse cursor (relative to the top left of the DIV). I am using
event.offsetX and event.offsetY to get the position of the mouse within the
DIV element. This works great, as long as there is no object inside the DIV. When I
add an image in the DIV, as soon as the cursor passes over that image,
offsetX and Y become 0 again.

How can I get the event.offsetX and event.offsetY to always be reported in
relation to my parent DIV element?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


How about placing the object in a DIV of it's own, and then overlay your mouse recording DIV over the top of that?

WebDvlpAuthor Commented:
Pfffffew... there must be an easier solution... I don't know how many and what kind of elements there will be in the DIV.
Maybe I should ask what you're doing with the cursor position information once you have it... it's tied to the content in the DIV?

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

WebDvlpAuthor Commented:
I just want to know on which position the cursor is in the div, relative to the top and left of the div. This works file with offsetx and offsety, but not when there are elements inside the container div.
Then an overlay should work fine. Just layout your page, and then put a new, transparent layer over the whole thing and get your mouse position in that one.
WebDvlpAuthor Commented:
Do you have some cross browsr code?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.