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
2010-09-30 20:23:24
That worked. Thanks. I love jQuery
Shyju
2010-09-30 20:26:45
+1
A:
$(function(){
var count =$('select#myID > option').size();
alert(count);
});
frictionlesspulley
2010-09-30 20:35:40
@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
2010-09-30 20:39:28