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!
cat.add(dog).hide()
You can use the add
method to add elements to an existing selector:
var dog = $('#dog'),
cat = $('#cat');
dog.add(cat).hide();
Just do this:
var $1 = $("#cat"), $2 = $("#dog");
$.each([$1, $2], function(t){ $(this).hide()} )
This scales to as many DIVs as you might need.
精彩评论