Skip to main content
deleted 157 characters in body
Source Link
Nick Craver
  • 631.4k
  • 138
  • 1.3k
  • 1.2k

You can use the :selected selector to select them, then get the .length, like this:

var count = $("#mySelect :selected").length; 

Or, alternatively since a <select multiple> returns .val() as the array of selected values:

var count = $("#mySelect").val().length; 

You can use the :selected selector to select them, then get the .length, like this:

var count = $("#mySelect :selected").length; 

Or, alternatively since a <select multiple> returns .val() as the array of selected values:

var count = $("#mySelect").val().length; 

You can use the :selected selector to select them, then get the .length, like this:

var count = $("#mySelect :selected").length; 
Source Link
Nick Craver
  • 631.4k
  • 138
  • 1.3k
  • 1.2k

You can use the :selected selector to select them, then get the .length, like this:

var count = $("#mySelect :selected").length; 

Or, alternatively since a <select multiple> returns .val() as the array of selected values:

var count = $("#mySelect").val().length;