Reputation: 5
This isn't working for me:
$('select').each(function() {
alert($(this).find('option').attr('selected').length);
}
actually what I really need is to just detect if the present select has any preselected options.
Upvotes: 0
Views: 69
Reputation: 262939
You can use the :selected selector:
alert($(this).find("option:selected").length);
Or, alternately, using this
as the selector's context:
alert($("option:selected", this).length);
Upvotes: 3