JQuery attribute Operation-Val () method

Source: Internet
Author: User

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.

  • index -optional. Accepts the index position of the selector.

  • oldvalue -Optional. Accepts the current Value property of the selector.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.