Two differents OnClick on two divs, one over the other

后端 未结 6 1554
心在旅途
心在旅途 2020-12-06 06:50

I have two divs, a big one and a smaller over the other, each div has its own OnClick method. The problem I have is when I clicked the smaller div, the big div\'s OnClick me

6条回答
  •  一整个雨季
    2020-12-06 07:15

    This worked for me in Jquery:

    $('#outer_div').click(function(event) {
        if(event.target !== event.currentTarget) return;
        alert("outer div is clicked")                   
    
    });
    

    This way, if the current target is not the same as the outer div, it will do nothing. You can implement normal functions for the child element.

提交回复
热议问题