Bart Az.
Bart Az.

Reputation: 1645

selecting multiple jQuery objects

I'm saving some objects as variables like this:

var $var1 = $(".class1"),
    $var2 = $(".class2");

Normally I would select the same elements like this:

$(".class1, .class2");

But since they're already available as a variables, is it possible to select them somehow like this?

$($var1, $var2);

Every function I'm firing on such collection applies only to the first variable

Upvotes: 1

Views: 37

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

you can use .add()

$var1.add($var2).dosomethig

Upvotes: 4

Related Questions