views:

45

answers:

2

How can i get the number of items(option) in a HTML select box in jQuery ?

+5  A: 

You can use .length to see how many elements a selector matched, for example:

var count = $("#selectID option").length;
Nick Craver
That worked. Thanks. I love jQuery
Shyju
+1  A: 
$(function(){
     var count =$('select#myID > option').size();
     alert(count);

});
frictionlesspulley
The > is superfluous, no?
ScottE
@ScottE - Actually, the `>` in this case should probably not be used since an `<option>` isn't necessarily a direct child of the `<select>`.
patrick dw