hi guys
How can i know is there any options in a combobox/selectbox or not?
small Edit:
i have my comboxbox as myCombo = $("#country");
now i want to know how many options are there in myCombo
hi guys
How can i know is there any options in a combobox/selectbox or not?
small Edit:
i have my comboxbox as myCombo = $("#country");
now i want to know how many options are there in myCombo
You can use the length
property like this:
alert($('#dropdown_id option').length);
Make sure to wrap your code in ready handler:
$(function(){
alert($('#dropdown_id option').length);
});
You can also use the size()
method:
$(function(){
alert($('#dropdown_id option').size());
});
In jQuery:
if($('select#something option').length > 0) {
// There are some.
...
<select id="mySelect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
Then:
alert($('#mySelect > option').size()); //4