Using jQuery to search for an item at a specific position?

Is there a way in jQuery to select an element located at a specific position?

For example, can I select the element that is on the left: 100 and above: 300 in the absolute position?

It would be nice if I could choose an element located in the position range, for example, select the element that is on the left: 100 - 150 px top 200 - 280px.

+43
javascript jquery
Oct. 15 2018-10-15
source share
2 answers

You are looking for the .elementFromPoint() JavaScript / DOM method.

 var elem = document.elementFromPoint(100, 100) // x, y 

This returns a DOM node , which of course can be wrapped in a jQuery object:

 $(elem).remove(); // for instance 

I am not aware of cross-browser compatibility, and I would like some guys to know how best to edit this post or write a comment about it.

Link: .elementFromPoint ()

Link example: http://www.jsfiddle.net/YjC6y/22/

+73
Oct 15 '10 at 13:52
source share
— -

If you know the exact coordinates relative to the document:

 function getElsAt(top, left){ return $("body") .find("*") .filter(function() { return $(this).offset().top == top && $(this).offset().left == left; }); } 

Another answer stops at the first overlay.

+7
Oct 01 '13 at
source share



All Articles