jquery modifies the property value instance code (sets the property value) _jquery

Source: Internet
Author: User

Set Properties -attr ()

The JQuery attr () method is also used to set/change property values.

The following example shows how to change the value of the href attribute in a link (set):

Instance

Copy Code code as follows:

$ ("button"). Click (function () {
$ ("#keleyi"). attr ("href", "http://www.jb51.net");
});

The attr () method also allows you to set multiple properties at the same time.
The following example shows how to set the href and title properties at the same time:


Instance

Copy Code code as follows:

$ ("button"). Click (function () {
$ ("#keleyi"). attr ({
"href": "Http://www.jb51.net",
"title": "Collayi Net"
});
});

callback function for attr ()

The JQuery Method attr () also provides callback functions. The callback function consists of two parameters: the subscript for the current element in the selected element list, and the original (old) value. Then return the string you want to use with the new value of the function.

The following example shows the attr () method with a callback function:

Instance

Copy Code code as follows:

$ ("button"). Click (function () {
$ ("#keleyi"). attr ("href", function (I,origvalue) {
return origvalue + "/jquery";
});
});

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.