Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use .each() on the select’s option collection to process every option, or add :selected to process only the current selection. Read an option’s submitted value with .val() and its visible label with .text().

Loop through every option

Select the options and call jQuery’s .each() method. Its callback receives a zero-based index, and this refers to the current option DOM element:

$('#mySelect option').each(function (index) {
  console.log(index, $(this).val(), $(this).text());
});

This logs each option’s index, value, and label. Returning false from the callback stops the iteration early.

Loop through selected options only

Add :selected to the option selector to visit only selected options. This works for a single select and for each selected item in a multiple select:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
$('#mySelect option:selected').each(function () {
  console.log($(this).val(), $(this).text());
});

:selected is a jQuery extension for matching selected <option> elements. If useful for your selector, start with the standard option selector and filter the collection:

$('#mySelect option').filter(':selected').each(function () {
  console.log($(this).text());
});

Read the submitted value or visible label

An option has two useful pieces of information: its value, which is submitted with the form, and its text, which is shown as the label. Use .val() for the value and .text() for the displayed text:

Rank #2
Sale
JavaScript and jQuery: Interactive Front-End Web Development
  • JavaScript Jquery
  • Introduces core programming concepts in JavaScript and jQuery
  • Uses clear descriptions, inspiring examples, and easy-to-follow diagrams
const value = $('#mySelect option:selected').val();
const label = $('#mySelect option:selected').text();

For a multiple select, calling $('#mySelect').val() returns an array of selected values. In jQuery 3.0 and later, it returns an empty array if no options are selected. To collect selected labels, iterate the selected options or map their text.

Handle selection changes

Attach a change handler when you need to read the selection whenever the user changes it. This example records both selected values and visible labels:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$('#mySelect').on('change', function () {
  const values = $(this).val();
  const labels = $(this).find('option:selected').map(function () {
    return $(this).text();
  }).get();
  console.log({ values, labels });
});

For a single select, values is the selected value; for a multiple select, it is an array. The mapped labels are collected into an array by .get().

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use .each()

Use explicit iteration when your code needs to do something separately for each option, access its index or element, or stop early. If a jQuery method already operates on every matched element, an extra loop is unnecessary. For example, this adds a class to all options in the collection:

$('#mySelect option').addClass('highlight');

Use $(selector).each(...) for a jQuery collection of DOM elements. jQuery’s separate $.each(...) function is intended for iterating arrays and objects.

Quick Recap

SaleBestseller No. 1
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05
SaleBestseller No. 2
JavaScript and jQuery: Interactive Front-End Web Development
JavaScript and jQuery: Interactive Front-End Web Development
JavaScript Jquery; Introduces core programming concepts in JavaScript and jQuery; Uses clear descriptions, inspiring examples, and easy-to-follow diagrams
$22.80

Quick reference

Need Use Result
Visit all options $('#mySelect option').each(...) Runs once per option
Visit selected options $('#mySelect option:selected').each(...) Runs once per selected option
Read a selected value $('#mySelect').val() A value for a single select; an array for a multiple select
Read selected label text $('#mySelect option:selected').text() Visible text for the matched selected option or options
Apply a collection method $('#mySelect option').addClass('highlight') Applies to the matched options without an explicit .each()

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.