Categories
JavaScript Answers

How to get element at specified position with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *