Code:
$(document).ready(function() {
$('a.data-window').click(function() {
//Getting the variable's value from a link
var loginBox = $(this).attr('href');
//Fade in the Popup
$(loginBox).fadeIn(300);
//Set the center alignment padding + border see css style
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
// When clicking on the mask layer the popup closed
$('#mask').live('click', function() {
$('#mask , .data-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
});
I have this piece of code which creates popup box with black mask. That part works ok, but what doesn't work is the part where all this should vanish when I click outside the box, on the black mask. Why won't it close?