How do I check how many options there are in a dropdown menu?
$("#mydropdown option").length
Or if you already got a reference to it,
$(myDropdown).find("option").length
var length = $('#mySelectList').children('option').length;
or
var length = $('#mySelectList > option').length;
This assumes your <select>
list has an ID of mySelectList
.
- http://api.jquery.com/length/
- http://api.jquery.com/children/
- http://api.jquery.com/child-selector/