I suppose the title is quite self-explanatory.
I want to close a div when a user clicks on an overlay OR on a link. I know you can just write two functions like so:
$("#close-search").click(function() {
$("#branding #searchform").fadeOut("fast");
$("#global-overlay").fadeOut("fast");
});
$("#global-overlay").click(function() {
$(this).fadeOut("fast");
$("#branding #searchform").fadeOut("fast");
});
Or you can write one function, like so:
function closeSearch {
$(this).fadeOut("fast");
$("#branding #searchform").fadeOut("fast");
}
$("#close-search").click(function() {
closeSearch();
});
$("#global-overlay").click(function() {
closeSearch();
});
I tried this, but it didn't work.
$("#close-search", "#global-overlay").click(function() {
$("#branding #searchform").fadeOut("fast");
$("#global-overlay").fadeOut("fast");
});
But is it possible to write this in one line? (Something like $("#close-search" OR #global-overlay")
)
comma seperated means this or that
$("#close-search, #global-overlay")
Multiple selector
Try this
$("#close-search, #global-overlay").click(function() {
$("#branding #searchform").fadeOut("fast");
$("#global-overlay").fadeOut("fast");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With