I've got a simple modal box opening like this:
<div id="social" class="overlay">
<div class="inner">
<a class="close" href="#"><span class="icon-close"></span></a>
CONTENT
</div>
</div>
Here's the CSS:
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 100;
background: fade(@black, 75%);
display: none;
z-index: 999;
}
#social .inner {
margin: 0 auto;
z-index: 1000;
width: 380px;
}
And here is the JS:
$(document).ready(function(){
$("#social").css("height", $(document).height());
$(".social").click(function(){
$("#social").fadeIn();
return false;
});
$(".close").click(function(){
$("#social").fadeOut();
return false;
});
});
The modal box closes when someone clicks on the link with the class close
. I'd like the modal box to also close when someone clicks anywhere outside the modal box, so anywhere on the overlay layer (z-index:999
). I don't know how to target the lower layer (z-index:999
) without also affecting the top layer (z-index:1000
).
I don't know much about jQuery, so if you could phrase your suggestions in a newbie way, that'd be great. Thanks! :)