Sometimes, we want to get element at specified position with JavaScript.
In this article, we’ll look at how to get element at specified position with JavaScript.
How to get element at specified position with JavaScript?
To get element at specified position with JavaScript, we can use the elementFromPoint
or elementsFromPoint
methods.
For instance, we write
document.elementFromPoint(x, y)
to get the element at point with xy coordinates x
and y
.
And we write
document.elementsFromPoint(x, y)
to get all elements at point with xy coordinates x
and y
.
Conclusion
To get element at specified position with JavaScript, we can use the elementFromPoint
or elementsFromPoint
methods.