views:

53

answers:

1

High all, I was wondering if it was possible to select an on page element via its coordinates?

reason being i'm trying to make an editable page where you can right click on highlighted elements, menu appears and then select from the options give. using the only method i could find that worked to select the element via hover it uses (event.target) which if having lots of parents combined with other code, it loops through and looses other data along the way. If i can find another method for highlighting the elements that would be of course better.

A: 

This is a terrible way to go about doing what you are trying to do, and I speak from experience: I inherited a calendar tool that figures out what day of the month you clicked on based on your mouse co-ordinates. The stupid thing certainly works, but it's a giant PITA to maintain/modify/add to in any way.

The much, much better way to go about it (unless you want a maintenance nightmare in your future) is to use the event object. If you hook up your events to the correct objects and use e.target (or, if you use jQUery, "this") you should be able to very easily route the correct actions based on the where the user clicked, without any coordinate nonsense.

machineghost