Reputation: 1775
I have a dinamically build array of classes:
var classes = new Array();
classes.push('class1');
classes.push('class2');
classes.push('class5');
and would like to select with jquery any element, that has all of those classes (but not only those classes), eg:
<a class="class1 class2 class5 class10 class18">my element</a>
How should I slove that?
Upvotes: 2
Views: 1485
Reputation: 535
You can try this color is your array of class names here is piece of code
for ( var i = 0; i < color .length; i++ )
{
if ( $(this).hasClass( color[i] ) )
{
break;
}
}
also check out this http://api.jquery.com/jQuery.inArray/
Upvotes: 0
Reputation: 382394
You may get your elements with
$('.'+classes.join('.'))
In your case, the resulting selector would be ".class1.class2.class5"
.
Note that this assumes there is at least one element in your classes
array.
Upvotes: 7