BN83 BN83 - 1 month ago 8
HTML Question

Form in popup, disabling child click to close blocking checkbox

I have a popup window that has a form in it and to stop the popped up div clicks from closing the window I've used:

$(".popup").click(function () {
$(".popup").css("display", "none");
}).children().click(function(e) {
return false;
});


However this works perfectly except with checkboxes whereby it disables checking them.

Is there any way around this?

popup is an overlay, then popupInner holds the form.

Answer

Try replacing your code with this:

$(".popup").click(function(e) {
    if (e.target == this) $(this).hide();
});

It would hide the popup only if clicked on the element with class popup and not its children, while it should also keep the functionality of the children.

Comments