Tuesday, April 30, 2024
HomeTechnologySoftwareDocument.elementFromPoint

Document.elementFromPoint

Date:

Related stories

Brooklinen’s Big Birthday Sale | Cup of Jo

At the end of a long day, nothing...

AI, Machine Learning Power Lead-Gen Tool From Realeflow

Seller predictive analytics company Realeflow has announced its...

Sarah Hudson Pierce: The effects of sleep deprivation

According to the CDC thirty -six percent or...

Free Printable To-Do List Template

Last updated: April 29, 2024 by the Homemade...
spot_imgspot_img

Reacting to events with JavaScript is the foundation of a dynamic experiences on the web. Whether it’s a click event or another typical action, responding to that action is important. We started with assigning events to specific elements, then moved to event delegation for efficiency, but did you know you can identify elements by position on the page? Let’s look at document.elementFromPoint and document.elementsFromPoint.

The document.elementFromPoint method accepts x and y parameters to identify the top-most element at a point:

const element = document.elementFromPoint(100, 100);
// 

If you want to know the entire element stack, you can use document.elementsFromPoint:

const elements = document.elementFromPoint(100, 100);
// [
, , ]

The elementFromPoint and elementsFromPoint are really helpful for experiences where developers don’t want to assign individual events. Games and entertainment sites could benefit from these functions. How would you use them?

  • An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer…

  • Animating CSS3 Transforms with MooTools Fx


Source link

Latest stories

spot_img