Instance
Set the value of the input field:
$ ("button"). Click (function () {$ (": Text"). Val ("Hello World");});
Try it yourself.
Definition and usage
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 mostly used for input elements.
If the method does not set a parameter, the current value of the selected element is returned.
Grammar
$ (selector). Val (value)
Parameters |
Description |
Value |
Optional. Specifies the new content of the selected element. |
Returns the Value property
Returns the value of the first matching element of the property of value.
Grammar
$ (selector). Val ()
Try it yourself.
Set the value of the Value property
$ (selector). Val (value)
Parameters |
Description |
Value |
Sets the value of the Value property. |
Try it yourself.
Use a function to set the value of the Value property
$ (selector). val (function (Index,oldvalue))
Try it yourself.
Parameters |
Description |
function (Index,oldvalue) |
Specifies the function that returns the value to be set.
|
JQuery Property Operation Reference Manual
JQuery API Function Reference:
Http://api.jquery.com/val/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DAttributes%2Fval%26redirect%3Dno
JQuery attribute Operation-Val () method