使用jQuery在特定位置查找元素? [英] Using jQuery to find an element at a particular position?

查看:102
本文介绍了使用jQuery在特定位置查找元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery中是否有方法可以选择位于特定位置的元素?

Is there a method in jQuery to select an element located at a particular position?

例如,我可以选择位于左侧的元素:100和顶部:300绝对位置?

For example, can I select the element that is located at left:100 and top:300 in absolute position?

如果我可以选择位于一系列位置的元素,那将是很好的,例如,选择左边的元素: 100 - 150 px top 200 - 280px。

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

推荐答案

您正在寻找 .elementFromPoint() JavaScript / DOM方法。

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

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

返回 DOM节点,其中当然可以包装成一个jQuery对象:

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.

参考:。elementFromPoint()

示例链接:http://www.jsfiddle.net/YjC6y/22/

这篇关于使用jQuery在特定位置查找元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆