Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsUse .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.
#1 Best Overall
- 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
- 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.
$('#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().
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
Best Value
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.
Recommended Free Tools

