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

H

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.

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me