How to count the number of options in a select box using JQuery

1 Comment

This can be done using the jQuery length property

You will use the following command to determine if there are any options within the select box.

var length = $('#selectBoxId > option').length;
console.log(length);

#selectBoxId should be replaced with the ID of your select box.

Image Credits: Photo by Isis França on Unsplash.

Last Updated On March 21, 2018

Related Articles

No results found

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
PavelB Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
PavelB
Guest
PavelB

Thanks, this helped. However, if there are optgroups in select, this command will ignore them and options inside them.

Menu
Copy link