Aakash
Aakash

Reputation: 675

How to get element based on coordinates

Suppose i have coordinates like top: 995, left: 216. Now i want to get the element in the DOM which is in this position (or an element of a particular class which is closest to this element) . Something like:

var element = coordinates().closest('this class');

How to achieve this is javascript (jquery or angularjs solution would also work).

Thanks

Upvotes: 0

Views: 173

Answers (1)

Rayon
Rayon

Reputation: 36609

Use Document.elementFromPoint()

The elementFromPoint() method of the Document interface returns the topmost element at the specified coordinates.

var element = document.elementFromPoint(x, y);

Upvotes: 4

Related Questions