views:

60

answers:

1

Hello guys,

Is there a method in jquery to select an element located at a particular position for example select the element that is located at left:100 and top:300 ? in absolute position

It would be nice if I could select and element located in a range of positions,

for example select the element that is located left: 100 - 150 px top 200 - 280px

Thank you guys

+4  A: 

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

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

That returns a DOM node, which of course then can be wrapped into a jQuery object:

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

I'm not that aware about the cross-browser compatibility and I would like some guys who know better to edit this post or write a comment about it.

Reference: .elementFromPoint()

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

jAndy
Wow! Never knew that. Excelent!! Learn something new every day.
John Hartsock
Thanks but this doesn't work in IE6
Thomas John
@Thomas: that is pretty possible.
jAndy
in IE with the code : var elem = document.elementFromPoint(100, 100)alert(elem); it alerts Object, but nothing with alert(elem.id); it alerts the id in both FF and chrome
Thomas John