1

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

1 Answer 1

4

you can use .add()

$var1.add($var2).dosomethig
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.