Find index of selected option

jQuery code snippet to find the index of the option that has been selected from within a select element.

$('select').change(function() {
  $('#output').text( $(this).children().index( $(this).children(':selected') ) );
}).trigger('change');

Use jQuery's index function to return the index of the item that matches the ':selected' selector within the children of the select element.

Example:

Reply

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Sorry, but this is needed to help us keep out spam
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.