Element at a specific point on the page
As I recently discovered,
Document.elementFromPoint() provides a pretty interesting and straightforward solution. It allows you to get the element at a specific point on the page and it also works quite well with
iframes, too. Additionally,
Document.elementsFromPoint() provides similar functionality, but returns an array of all the elements at a specific point on the page, in order of their z-index.
// Returns the topmost element at the specified coordinates const element = document.elementFromPoint(x, y); // Returns an array of all the elements at the specified coordinates const elements = document.elementsFromPoint(x, y);