Click this OR that, then do something

jquery, selector

Solution

comma seperated means this or that

$("#close-search, #global-overlay")

Multiple selector

Problem

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")`)

Original source