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

99
Vistas
Forward a click event to the element behind

I have two divs stacked together and one is behind the other.

<div style='position:relative;'>
  <div style='position: absolute; top:0; left:0;'>
    bottom element
  </div>
  <div style='position: absolute; top:0; left:0;'>
      top element
  </div>
</div>

I installed a click listener to both elements. However, only the top one gets the event. Some other posts suggest that I can use pointer-event:none to give up handling the click event from the top element. However, I want to handle the click events in both elements.

https://jsfiddle.net/zhu63v7o/

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'd love to see your JavaScript code but never the less, you can use the z-index property with the conditional statement for this. Also note that the container for both divs should be the one receiving the event while the divs are responding to the event

//style

 .inner_div{
  width: 100px;
  height: 100px;
  position: absolute;
  top: 0;
  left: 0;
}

//HTML

<div style="position: relative; width: 100px; height: 100px" onclick="myChange(document.querySelector('#one'))">
          <div class="inner_div" id="one" style="background: red">div 1</div>
          <div class="inner_div" id="two" style="background: green">div 2</div>
</div>

//Js

function myChange(x){
  if (x.style.zIndex == "1") {
    x.style.zIndex = "-1"
  }else{
    x.style.zIndex = "1"
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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