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

104
Views
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 answers
Answer question

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 Report
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!