.val() (since 1.0) gets or sets the current value of form elements — mainly input, select, and textarea. Prefer it over .prop("value") for form text and selection.
Remember
// Get
var name = $("#name").val();
var picks = $("#multi").val(); // array for multi-select
// Set
$("#name").val("Ada");
$("#multi").val(["a", "c"]);
// Callback (since 1.4)
$("input").val(function (i, v) {
return v.trim();
});
If handlers must run, chain .trigger("change") after setting.
Signature
Since
Role
.val()
1.0
Get value of first element
.val(value)
1.0
Set value on every match
.val(fn)
1.4
Set from function(index, oldValue)
Multi-select get
—
Array of values · [] if none (jQuery 3.0+)
Pseudocode
Pseudocode
if called as .val():
if no matched elements: return undefined
if first element is multi-select:
return array of selected option values
// jQuery 3.0+: [] when nothing selected
else:
return that element's current value
if called as .val(value):
for each matched element:
set its value / selected / checked state from value
// does NOT fire change — call .trigger("change") if needed
if called as .val(fn):
for each matched element with index i:
set value to fn(i, currentValue)
Reference
Cheat Sheet
Keep these facts handy while reading form values.
Topic
Detail
Primary use
input, select, textarea
Getter scope
First element only
Empty collection
undefined
Multi-select (3.0+)
Array · empty → []
Set + events
No auto change — use .trigger("change")
Array setter
Selects options / checks matching values
vs .prop("value")
Prefer .val() for forms
Checked state
Use .prop("checked"), not .val()
Try it
Live Preview
Get or set the sample input value — same APIs as the examples below.
Sample element: the text input below. Type freely, then run an action.
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Prefer .val() for form values.
Example 1 — Get Input Value on Keyup
Mirror whatever the user types — official getter pattern.
jQuery
$("input").on("keyup", function () {
var value = $(this).val();
$("p").text(value);
}).trigger("keyup");
single=Single2, multi=Multiple2,Multiple3
(matching checkboxes/radio also selected)
How It Works
String. Sets one select option or text field.
Array. Matches option/input values to check or select.
Radios. Only one value in the group stays selected.
Events. Still no automatic change event.
Edge Cases & Pitfalls
These trip up beginners most often with form values.
events
.val() does not fire change
Programmatic sets skip handlers. Chain .trigger("change") when needed.
multi
Empty multi-select changed in 3.0
jQuery 3.0+ returns []; older versions returned null. Use || [] when supporting both.
boolean
.val() ≠ checked state
Use .prop("checked") or :checked to test whether a box is on. .val() returns the value attribute.
textarea
Newline normalization
Browsers may strip \r from textarea .val(). A $.valHooks.textarea can normalize if you need CRLF.
Compatibility
Browser Support
.val() has been part of jQuery since 1.0. Callback setter since 1.4. Multi-select empty result is [] since 3.0. Works wherever your loaded jQuery build runs.
✓ Stable · jQuery 1.0+
jQuery .val()
Universal across browsers that run your jQuery version. Prefer current jQuery 3.x+ for consistent multi-select empty arrays.
100%jQuery core
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.val()Universal
Bottom line: Safe for everyday forms. Prefer .val() for field values; use .prop() for live checked/disabled state.
Analysis
Performance Notes
Approach
Cost
Best for
One .val() get/set
Cheap
Typical form UI
Array set on a small group
Cheap
Multi-select / checkbox groups
Reading every keystroke on huge pages
Watch
Debounce or target one field
Value access is inexpensive. Keep handlers focused on the fields you need — avoid scanning the whole document on every keyup.
Remember
Key Takeaways
Role: get/set form values on inputs, selects, and textareas.
Multi-select: returns an array · empty is [] in jQuery 3.0+.
Events: set does not fire change — trigger it yourself.
State: use .prop("checked") for on/off, not .val().
One line:.val() is jQuery’s form-value API — get/set text and selections, then trigger change only when you need it.
Frequently Asked Questions
.val() gets or sets the current value of form elements — input, textarea, and select. The getter returns the first match (string, number, or array for multi-select). The setter updates every matched element. Available since jQuery 1.0; callback setter since 1.4.
.val() is jQuery's form-value API and handles selects, checkboxes, and radios — including array values for multi-select. Prefer .val() for form text and selection. Use .prop() for live boolean state like checked or disabled.
An array of each selected option's value. Since jQuery 3.0, no selection returns []. Before 3.0 it returned null.
No. Call .trigger("change") after .val(newValue) if change handlers must run.
undefined. Check that your selector matched elements before reading.
Use $("input[name=foo]:checked").val(). For whether it is checked (boolean), use .prop("checked") or .is(":checked").