最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to hide elements defined as variables? - Stack Overflow

programmeradmin6浏览0评论

I have two variables defined as:

var div1 = $("#div1");

var div2 = $("#div2");

I know that I can use $("#div1, #div2").hide() to hide both div

But is there a way I can hide them through defined variables like (div1, div2).hide()?

I have two variables defined as:

var div1 = $("#div1");

var div2 = $("#div2");

I know that I can use $("#div1, #div2").hide() to hide both div

But is there a way I can hide them through defined variables like (div1, div2).hide()?

Share Improve this question edited Feb 1, 2015 at 16:42 Deduplicator 45.8k7 gold badges72 silver badges123 bronze badges asked Apr 16, 2013 at 10:10 user2285885user2285885 1
  • possible duplicate of Combine two selectors with one jQuery object – gdoron Commented Apr 16, 2013 at 10:13
Add a ment  | 

2 Answers 2

Reset to default 9

You could use .add() method:

div1.add(div2).hide();

You can use the add() method to add other elements to existing selector:

div1.add(div2).hide()
发布评论

评论列表(0)

  1. 暂无评论