Possible Duplicate:
Locating DOM element by absolute coordinates
I want to find out the list of all the DOM Elements that are located at the position where my mouse is clicked. I require to do this using javascript or jquery. Could someone suggest me on how I could do this?
The easiest way to find an HTML element in the DOM, is by using the element id.
The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.
One of the most common methods to access an element in HTML DOM is getElementById() which accesses an element based on the value of its ID attribute. The value of the ID attributes are supposed to be unique and no two elements on a single HTML page should have similar IDs.
I'd use jQuery to do this, starting at the clicked element and getting a list of all the clicked elements. Add a handler to the document on the mouse click:
$( document ).click( function( event ) {
// event.currentTarget is the clicked element
// this is a list of all the parents of the clicked element
$( event.currentTarget ).parents();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With