How do I check how many options there are in a dropdown menu?

Asim Zaidi picture Asim Zaidi · Jul 26, 2010 · Viewed 153.9k times · Source

How do I check, using jQuery, how many options are there in a drop down menu?

Thanks.

Answer

user113716 picture user113716 · Jul 26, 2010
var length = $('#mySelectList').children('option').length;

or

var length = $('#mySelectList > option').length;

This assumes your <select> list has an ID of mySelectList.