I can't seem to get this to stop propagating..
$(document).ready(function(){
$("body").on("click","img.theater",function(event){
event.stopPropagation();
$('.theater-wrapper').show();
});
// This shouldn't fire if I click inside of the div that's inside of the
// `.theater-wrapper`, which is called `.theater-container`, anything else it should.
$(".theater-wrapper").click(function(event){
$('.theater-wrapper').hide();
});
});
Since you are using
onon thebodyelement and not directly onimg.theaterthe event is going to bubble up tobodyelement and that is how it works.In the course of event bubbling
.theater-wrapperelementsclickevent will be triggered so you are seeing it.If you are not creating any dynamic elements then attach the click event handler directly on
img.theaterelement.Alternatively you can check the target of the
clickevent inside.theater-wrapperelementsclickhandler and do nothing.