Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Send mouseover event to all overlaid elements

Does anyone know how to propagate/trigger the mouseover event to multiple children when they appear overlaid on top of each other? Is it even possible?

I'm trying to get mouseover to be triggered for 2 overlaid elements. I've written a basic example to demonstrate the problem:

example-output

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <style>
    body {
      background-color: black;
    }
    .relative {
      position: relative;
    }
    .child-1,
    .child-2 {
      position: absolute;
      width: 200px;
      height: 200px;
    }
    .child-1 {
      top: 0;
      left: 0;
      background-color: rgba(255, 255, 0, 0.5);
    }
    .child-2 {
      top: 50px;
      left: 50px;
      background-color: rgba(0, 255, 255, 0.5);
    }
  </style>

  <body class="relative">
    <div class="child-1">1</div>
    <div class="child-2">2</div>
  </body>

  <script>
    const child1 = document.querySelector('.child-1');
    const child2 = document.querySelector('.child-2');

    child1.addEventListener('mousemove', () => console.log(1));
    child2.addEventListener('mousemove', () => console.log(2));
  </script>
</html>

Whenever I hover over just child 1, I get a log of 1. When I hover over just child 2, I get a log of 2. That all works. But when I hover over 1 and 2 where they overlap, I only get a log of which ever one is on top, in this case 2 (this can be flipped by adjusting the z-index or order in the DOM).

I found this answer, but changing the z-index or pointer-events: none doesn't help me because I need both the element's event to fire.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!