How to Count Total Items in DropDownList using JQuery

Waqas Anwar
11 January 2011

You have a DropDownList control and you want to count the total number of items in the DropDownList using JQuery. You can using following JQuery code snippet.

Here is the code for DropDownList control.
<asp:DropDownList ID="DropDownList1" runat="server" >
   <asp:ListItem Value="1">Germany</asp:ListItem>
   <asp:ListItem Value="2">France</asp:ListItem>
   <asp:ListItem Value="3">Brazil</asp:ListItem>

Following JQuery code snippet will give you total number of items in the above DropDownList control.
var items = $("#DropDownList1 option").length;