Change the selected value of a drop-down list with jQuery
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Changing the selected value of a select element with jQuery is usually as simple as calling .val(...) on the element. The two details that matter are whether the target option value actually exists and whether you also need to trigger the change event for other code to react.
In other words, changing the UI state and notifying the rest of the page are related but separate steps. A lot of bugs come from forgetting the second one.
The Normal Way: Use .val()
Suppose you have this drop-down list:
To select In Progress, use the option value:
That updates the selected option immediately. This is the standard jQuery answer because .val() is built for reading and writing form control values.
Trigger change If Other Logic Depends on It
Setting the value does not always run any change handlers that your application attached. If other code listens for change, trigger it explicitly.
This is important for forms that update previews, run validation, or enable and disable other controls when the user changes the selection.
For example:
Without .trigger("change"), the select box would show Done, but the event handler would not necessarily run.
Make Sure the Value Exists
If you set a value that is not present in any option, the selection will usually become empty or remain unchanged depending on browser behavior.
A safer pattern is to check first:
That keeps the UI state predictable and avoids silently selecting nothing.
Selecting by Text Instead of Value
Sometimes you only know the displayed label, not the option value. In that case, locate the matching option and mark it selected.
This works, but selecting by value is usually better because values are stable while visible labels may change for localization or wording updates.
Handling Dynamic Options
If options are added asynchronously, set the value only after the options exist.
Trying to set the value before the option is inserted is a common reason the selection "doesn't work."
Multi-Select Elements Use the Same API
For a multi-select control, the pattern is the same, but .val() takes an array of option values.
That is useful because many developers reach for manual loops even though jQuery already supports the common multi-select case directly.
Common Pitfalls
- Calling
.val(...)and expecting attachedchangehandlers to fire automatically. - Setting a value that does not exist in the option list.
- Selecting by visible text when a stable option value was available.
- Trying to update the selection before dynamically loaded options have been inserted.
- Mixing raw DOM methods and jQuery code in ways that make event behavior inconsistent.
Summary
- Use
$(selector).val(value)to change the selected option by value. - Add
.trigger("change")when other code needs to react to the update. - Check that the option value exists before setting it.
- Prefer selecting by
valuerather than by display text. - For dynamic lists, make sure the option is present before trying to select it.
Related reading
- Changing data structure representation at runtime looking for other examples
- Changing the tick frequency on the x or y axis
- Check if 2 tree nodes are related ancestor/descendant in O1 with pre-processing
- Check if a Bash array contains a value
- Changing On3 to On2 in JavaScript
- Changing the color of an hr element
- Check if a binary tree is a mirror image or symmetric
- Check if a given key already exists in a dictionary

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.