There are two usage of jQuery val() method.
It is used to get value.
It is used to set value.
It is used to set value using function.
Parameters of jQuery val() method
jQuery val() example
The val() method is primarily used to get the values of form elements. This method doesn't accept any arguments. This method returns a NULL when no option is selected and it returns an array containing the value of each selected options in the case of one or more selection.
Let's see the example of val() method.Test it Now
Let's see example of jQuery val() method with single and multiple select boxes.Test it Now
jQuery val(value) example
This method is used to set a string of text, a number, an array of strings corresponding to the value of each matched element. This method facilitates you to set the value by passing in the function.
Let's see the example of val(value) method.Test it Now