You will have to trigger a click on the other image. When it comes to mouse events, it's the structure and not the position that matters.
$(function(){
$("#bg").on("click", function(){
alert("Click on background");
});
$("#overlay").on("click", function(){
alert("Click on overlay - should bubble to background and container");
$("#bg").trigger('click');
});
$(".container").on("click", function(){
alert("Click on either overlay or background which bubbled through to the container");
});
});
Here is a forked fiddle. Note that this will cause the .container
click event handler to trigger twice. You can prevent this with return false
in the bg
handler. You will just have to make some adjustments depending on your actual use case.