Reputation: 7971
I want hide div which has id 'hide' and class 'test'. It is working fine with .filter
method but I want to is there another method to do this. fiddle
if($('#hide').hasClass('test')){
$('.test').hide();
}
or
$('#hide').filter(function(){
return this.className=='test'
}).hide();
Upvotes: 0
Views: 287
Reputation: 123739
You can write it as
$('#hide.test').hide();
no space between selectors will select the element which has id hide
and class test
Not quite clear on what you meant by dynamic but as @kolink said you can just concatinate them. If there are many classnames in an array you could even do.
var toHide = ["hide", "if", "allarepresent"];
$("#hide." + toHide.join('.')).hide();
Upvotes: 6