Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match all combinations of any classes in jQuery

I have two comma-separated selectors;

.class, .foo, .bar

.lorem, .ipsum, .potato

I'd like to be able to select any possible combination between these two groups. So it would select elements matching

.class.lorem
.class.ipsum
.class.potato
.foo.lorem
.foo.ipsum
.foo.potato
.bar.lorem
.bar.ipsum
.bar.potato

How can I achieve this effectively?

like image 437
Emphram Stavanger Avatar asked Jun 20 '12 15:06

Emphram Stavanger


1 Answers

Select all elements with any class from the first set, and then filter out the elements which don't have a class from the other set:

$('.class, .foo, .bar').filter('.lorem, .ipsum, .potato')
like image 159
Paul Avatar answered Nov 16 '22 00:11

Paul