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()
?
- possible duplicate of Combine two selectors with one jQuery object – gdoron Commented Apr 16, 2013 at 10:13
2 Answers
Reset to default 9You 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()