val() in jQuery
Using this method we can get the value of the first element in the set of matched elements.
This method does not cause the dispatch of the change event if setting the values.
Syntax 1 - Get the current value of the first element in the set of matched elements.
$(selector).val()
Syntax 2 - Set the value of each element in the set of matched elements.
$(selector).val(value)
- value - It represents a string of text, a number, or an array of strings corresponding to the value of each matched element to set as selected/checked.
Syntax 3 - A function returning the value to set
$(selector).val(function(index, currentValue))
- index - Index position of the element in the set.
- currentValue - The old value.