Reputation: 7782
I am not sure if "concatenate" is the correct term for it, but something like this:
$("#a").$("#b").$("#c").$("#d").click(); // click on all of them
Basically I have a long list of stuff but I can't apply a class to them.
Upvotes: 7
Views: 15236
Reputation: 303253
As in CSS, you can use a comma to separate multiple selectors:
$("#a, #b, #c, #d").click();
Note that these do not have to be the same kind of 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 the jQuery objects, you can add()
the sets like so:
var a = $('#a'), b = $('#b'), c = $('#c');
var all = a.add(b).add(c);
Upvotes: 17
Reputation: 69905
You can concatenate selectors using comma(,
) separator. Try this.
$("#a,#b,#c,#d").click();
Upvotes: 2