Anthony DeSimone
Anthony DeSimone

Reputation: 2034

Getting the number of selects with no option selected

I'm trying to count how many selects are still are their default blank value.

I've got this to count the selects:

$('select.fabricColorSelect').size()

How do I modify that to only count the selects whose selected option matches a blank string?

Upvotes: 0

Views: 34

Answers (2)

John Conde
John Conde

Reputation: 219804

Off of the top of my head, I think this will work:

$('select.fabricColorSelect option[value=""]:checked').size()

(yes, I meant :checked)

Upvotes: 2

PSL
PSL

Reputation: 123739

Assuming you want to select all the selects that has the default value of ("") as the selected option, You can use filter:

$('select.fabricColorSelect').
            filter(function()
               {
                    return this.value == "" // or $(this).val() == ""
               }).length;

Upvotes: 1

Related Questions