Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Target all except ___?

I'm looking for a way to select all elements on a page, except those with a specified DOM location.. Here's an example of what I'd like to do:

jQuery('*').except('.ignore').bind('click', function(e) { ... });

Is this possible in a "native jQuery" way?

like image 223
Dang Avatar asked Sep 23 '09 16:09

Dang


2 Answers

You want to use the :not() selector:

jQuery(":not(.ignore)").bind("click", function(e) { ... });
like image 182
Andrew Hare Avatar answered Oct 03 '22 00:10

Andrew Hare


Another way, if you already have selectors for both:

$('.foo').not('.ignore').bind(...);

Also, more filters.

like image 35
orip Avatar answered Oct 03 '22 02:10

orip