My HTML page features two consecutive divs. The first div contains a child span that has a relative position, causing it to overlap the second div.
I have implemented click events for both divs. However, when I click on the span that overlaps the second div, it triggers the click event for the first div instead of the intended second div.
Is there a way to ensure that clicking on the overlapping part of the span triggers the click event for the second div?
function div1Clicked() {
alert('div 1 clicked');
}
function div2Clicked() {
alert('div 2 clicked');
}
#div1 {
border: 1px solid gainsboro;
height: 100px;
width: 13%;
background: red;
display: inline;
float: left;
}
#div1 span {
width: 316px;
height: 30px;
background: green;
float: left;
margin-top: 39px;
position: relative;
}
#div2 {
border: 1px solid gainsboro;
height: 100px;
width: 13%;
background: red;
display: inherit;
float: left;
}
<div onclick="div1Clicked()" id="div1">
<span>
</span>
</div>
<div onclick="div2Clicked()" id="div2">
<div>
</div>
</div>