8

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

1

2 Answers 2

9

You could use .add() method:

div1.add(div2).hide();
Sign up to request clarification or add additional context in comments.

Comments

8

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

div1.add(div2).hide()

1 Comment

@NJason, The worse reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.