Shyju
Shyju

Reputation: 218732

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

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

Upvotes: 0

Views: 736

Answers (2)

frictionlesspulley
frictionlesspulley

Reputation: 12368

$(function(){
     var count =$('select#myID > option').size();
     alert(count);

});

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630389

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

var count = $("#selectID option").length;

Upvotes: 5

Related Questions