Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do a hide on two jquery variables at once (basic question)

Tags:

jquery

i cant seem to get this right and would like to know the exact syntax to use.

say i have two variables defined in jQuery

var cat = $('#cat');
var dog = $('#dog');

i want for example... hide both divs.

i know without the vars it would be $('#cat, #dog').hide(); no matter how i do it with the variables i cant get it to work.

(cat,dog).hide();

thanks!

like image 612
liz Avatar asked Nov 29 '10 17:11

liz


2 Answers

cat.add(dog).hide()
like image 121
Harmen Avatar answered Sep 19 '22 07:09

Harmen


You can use the add method to add elements to an existing selector:

var dog = $('#dog'),
    cat = $('#cat');
dog.add(cat).hide();
like image 22
bdukes Avatar answered Sep 20 '22 07:09

bdukes