.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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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();
});
Call
What it does
.val()
Get value of first element
.val(value)
Set value on every match
.val(fn)
Set from function(index, oldValue)
Multi-select get
Array of values · [] if none (jQuery 3.0+)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
value
Used in .val(value). Set value on every match
fn
Used in .val(fn). Set from function(index, oldValue)
Return Value
Return Value
Description
Boolean
Often true or false depending on the match or state.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
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: Single | Multiple: Multiple2, Multiple3
(updates on change)
How It Works
Single..val() returns the selected option value.
Multi. Returns an array of selected values.
3.0+. No selection → [] (older jQuery used null).
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").