I believe the title is pretty clear.
I want to close the div when the user clicks on the overlay OR by the link. I know that you can simply write two functions:
$("#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, for example:
function closeSearch { $(this).fadeOut("fast"); $("#branding #searchform").fadeOut("fast"); } $("#close-search").click(function() { closeSearch(); }); $("#global-overlay").click(function() { closeSearch(); });
I tried this, but it did not work.
$("#close-search", "#global-overlay").click(function() { $("#branding #searchform").fadeOut("fast"); $("#global-overlay").fadeOut("fast"); });
But is it possible to write this on one line? (Something like $("#close-search" OR #global-overlay") )
jquery selector
Bram vanroy
source share