开发者

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

开发者 https://www.devze.com 2023-01-27 16:50 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号