LoginSignup
47
36

More than 3 years have passed since last update.

X,Y座標で指定した位置にあるDOM要素を取得する

Last updated at Posted at 2015-08-26

document.elementFromPointメソッドで取得できる。

  • x:100, y:100の座標にあるエレメントを取得するサンプル
var X = 100;
var Y = 100;
var elm = document.elementFromPoint(X, Y);

console.log(elm); 

要素が重なっている場合は、z-indexで一番上にある要素が取得される。

  • マウス座標上の要素を取得するサンプル。
document.onmousemove = function (e){
    var elm = document.elementFromPoint(e.clientX, e.clientY);
    console.log(elm);
};

テストに使えるかも。

47
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
47
36