Val() method in Jquery
val() Method
The jQuery val() method is used to get or set the values of form fields, such as text boxes, dropdowns, and many other inputs. Getting and setting form field values is very useful in order to handle form events and validation.
Syntax:-
- Its syntax for returning value attribute is:- $(selector).val()
- Its syntax for setting value attribute is:- $(selector).val(value)
- Its syntax for setting value by function is:- $(selector).val(function(index,currentvalue))
Further Explanation:-
Parameter | Description |
---|---|
value | Required. Specifies the value of the value attribute |
function(index,currentvalue) | Optional. Specifies a function that returns the value to the set.
|