user2285885
user2285885

Reputation:

How to hide elements defined as variables?

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()?

Upvotes: 8

Views: 280

Answers (2)

Eli
Eli

Reputation: 14827

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

div1.add(div2).hide()

Upvotes: 8

xdazz
xdazz

Reputation: 160833

You could use .add() method:

div1.add(div2).hide();

Upvotes: 9

Related Questions