Reputation: 606
I have a random count of selects on page with the same class e.g. .selectWidth
and I need to check which select has not any options and for each select with no options do same function.
Upvotes: 1
Views: 31
Reputation: 78520
You can use .filter()
$('.selectWidth').filter(function(){
return this.options.length === 0;
}).each(function(){
// do something
});
<select class="selectWidth"></select>
<select class="selectWidth">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select class="selectWidth">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select class="selectWidth"></select>
<select class="selectWidth"></select>
Upvotes: 1
Reputation: 20740
You can select which has no option like following.
$('.selectWidth:not(:has(option))')
You can iterate through these using each like below.
$('.selectWidth:not(:has(option))').each(function() {
// do you stuff
})
Upvotes: 1