Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting multiple cached elements

In jQuery you can select two elements by id like: $('#elem, #elem2');

BUT

What if you have cached the elem and elem2, and what to apply the same method/function to them both?

i.e.

$elem = $('#elem'); $elem2 = $('#elem2');

This obviously wont work:

$($elem, $elem2)

Thanks!

like image 646
Globalz Avatar asked May 11 '10 03:05

Globalz


1 Answers

Use the add method:

$elem.add($elem2).show();
like image 61
Atanas Korchev Avatar answered Sep 19 '22 17:09

Atanas Korchev