Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a selector with multiple elements using Jquery closest()

I have a listener for click events from which I need to exclude some elements.

Right now my list is growing, so I'm looking for a better way to "bundle" multiple elements in a selector.

This is what I have:

$(document).on('click tap', function(event) {               
    if ($(event.target).closest('div:jqmData(panel="popover")').length > 0 ||
        $(event.target).closest('div.pop_menuBox').length > 0 ||
        $(event.target).closest('.toggle_popover').length > 0 ) ||
        $(event.target).closest('.ui-selectmenu').length > 0 {
          return; 
    }
    // do stuff
});

Is there a better way to exclude these elements?

Thanks for help!

like image 925
frequent Avatar asked Mar 21 '12 12:03

frequent


1 Answers

Use a comma.

if ($(event.target)
     .closest('div:jqmData(panel="popover"), div.pop_menuBox, .toggle_popover, .ui-selectmenu').length > 0) {
     return; 
}
like image 93
Daniel A. White Avatar answered Oct 25 '22 03:10

Daniel A. White