Switch selector in jQuery?

I'm not sure that "concatenate" is the right term for it, but something like this:

$("#a").$("#b").$("#c").$("#d").click(); // click on all of them 

I basically have a long list of things, but I can't apply a class to them.

+7
source share
4 answers

As in CSS , you can use a comma to separate multiple selectors :

 $("#a, #b, #c, #d").click(); 

Note that this should not be the same selector. For example:

 // Click the menu, all spans in all .foo, and paragraphs after headers $("#menu, div.foo span, h1 + p").click(); 

Also, if you already have jQuery objects, you can add() such as:

 var a = $('#a'), b = $('#b'), c = $('#c'); var all = a.add(b).add(c); 
+16
source
 $("#a, #b, #c, #d").click(); 

It is called comma :-D

+4
source

You can combine selectors with a comma separator ( , ). Try it.

 $("#a,#b,#c,#d").click(); 
+2
source

make a comma

 $("#a,#b,#c,#d").click() 
+1
source

All Articles