0

If I have this HTML:

<div id="outer-layer">
    <div id="inner-layer"></div>
</div>

And this JS:

$(document).ready(function () {
    $("#outer-layer").click(function(){
       // FUNCTION 1
    });   
    $("#inner-layer").click(function(){
       // FUNCTION 2
    });        
});

When I click #inner-layer, both FUNCTION 1 and FUNCTION 2 fire. Is there a way for only FUNCTION 2 to fire?

I expected only FUNCTION 2 to fire, but both functions fired.

  • 2
    Events "bubble up" through the DOM, so a "click" on the inner element will also fire the outer element handler. – Pointy Mar 12 '23 at 19:18

0 Answers0