Reputation: 233
When I click on a div a popup opens, and it closes when I click anywhere outside the popup. Because of this feature even when I click on 'Back to top button' the popup close and that I don't want. I want the popup to close on outside click but on click of few elements I want the popup to remain open.
My JS for reference:
$(document).click(function (e) {
if (!$(e.target).is('#myPanel, #myPanel*')) {
$("#myPanel").hide();
$(".span10").width(600);
}
});
Upvotes: 0
Views: 136
Reputation: 8578
You are on the right way. However, you need to include all elements that should not close the popup in the comma separated selector. Also, for those that have child elements, you need to include the ID followed by a star as well but separated by a space. The space is what is missing in your code. It should be #myPanel *
and not #myPanel
.
$(document).click(function (e) {
//Do not close popup for these:
// - Element with ID myPanel #myPanel
// - Any descendants of element with ID myPanel #myPanel *
// - Element with ID backtotop #backtotop
if (!$(e.target).is("#myPanel, #myPanel *, #backtotop")) {
$("#myPanel").hide();
$(".span10").width(600);
}
});
Upvotes: 1