Suppose an input code:
JS code is as follows:
Running results:
Extended data:
The val () method returns or sets the value of the selected element. The value of the element is set through the value property. This method is mainly used for input elements. If the method does not set parameters, the current value of the selected element is returned.
Use the function to set the Value of the value property:
$ (selector). Val (function (index, oldvalue))
Specify the function that returns the value to be set:
Index-Optional. Accept the index position of the selector.
Old value- optional. Accept the current value property of the selector.
References:
jquery - val()