getElement by position?

2019-06-26 01:09发布

I am working on SVG script

there are getElementById or getElementsByTagName

but I can't find any method to get elements by position

such as get the elements whose position is x=10,y=10.

is there any way I can achieve this?

3条回答
Explosion°爆炸
2楼-- · 2019-06-26 01:15
var yourElement = document.elementFromPoint(10, 10);

Here's a working example that changes the background colour of the element at the specified point.

Note that if the specified point is outside the visible area of the document, elementFromPoint will return null.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-26 01:26

You can try this:

$("svg").find("[x='10'][y='10']");

It will give all the elements with svg which have x = 10 and y = 10.

Working demo

查看更多
登录 后发表回答