Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the list of DOM elements that are located at a given position in the page [duplicate]

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?

like image 214
Abishek Avatar asked Oct 22 '12 04:10

Abishek


People also ask

What is the best way to locate an element in the DOM?

The easiest way to find an HTML element in the DOM, is by using the element id.

How do you identify DOM elements?

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.

How do I get the DOM element value?

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.


1 Answers

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();
}
like image 119
pwp2 Avatar answered Nov 15 '22 05:11

pwp2