I have used this JavaScript below:
This is working for me: I have an image inside of the modal window, so if someone click outside the image (centered):
html code:
ccs code:
#modal_div {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: transparent;
}
#image_in_modal_div {
left: 50%;
top: 30%;
position: absolute;
}
mixed jquery and javascript code:
$( document ).ready(function() {
$("#element_that_opens_modal").click(function(){
$("#modal_div").show();
});
window.onclick = function(event) {
if (event.target.id != "image_in_modal_div") {
$("#modal_div").hide();
}
}
});