jquery Modify attribute value Instance code

Source: Internet
Author: User

The JQuery attr () method is used to set/change the property value, and the following example shows how to change the value of the href attribute in the link (set)

Set Properties-The attr () 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: the instance code is 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://ww W.jb51.net "," title ":" Collayi Net "});     }); The attr () callback function, the JQuery method attr (), also provides a callback function. 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: the instance code is as follows: $ ("button"). Click (function () {$ ("#keleyi"). attr ("href", function (i,origvalue) {RET Urn 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.