Reputation: 33
I tried this but it's not working:
var a = $('a');
var b = $('p');
var c = $('div');
$(a, b, c).hide();
Upvotes: 3
Views: 121
Reputation: 25582
jQuery selectors work like CSS selectors. You can select multiple independent sets of elements if you separate their selectors with commas:
$('a, p, div').hide();
If you already have fetched the different sets, you have the option of re-fetching them together (above), running .hide()
on each one, or merging the sets to run .hide()
once:
a.add(b).add(c).hide();
For more information see the .add()
documentation.
Upvotes: 4