Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda