Get the current value of the first element in the set of matched elements or set the value of every matched element.
// <input value="Hello">
const val = $('input').val();
"Hello"
$('input').val('New Value');
<input value="New Value">
// <select multiple>...</select>
$('select').val(['option1', 'option2']);
// Options with values 'option1' and 'option2' are selected.
$('input').val((index, value) => value.toUpperCase());
// "hello" becomes "HELLO"
| Parameter | Type | Description |
|---|---|---|
| value | string | number | array | function | The value to set. For multiple selects or checkboxes/radios, pass an array of values. If a function, it is called with (index, currentValue). |
Returns: The value for getter, or the original SR object for setter.