Jquery modifying the property value instance code (setting the property value) _ jquery-js tutorial

Source: Internet
Author: User
The jQueryattr () method is used to set and change the property value. The following example shows how to change (SET) the value of the href attribute in the link. Set attributes-Attr ()

The jQuery attr () method is also used to set/change attribute values.

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

Instance

The Code is as follows:


$ ("Button"). click (function (){
$ ("# Keleyi"). attr ("href", "http://www.jb51.net ");
});


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


Instance

The Code is as follows:


$ ("Button"). click (function (){
$ ("# Keleyi"). attr ({
"Href": "http://www.jb51.net ",
"Title": "Ke leyi network"
});
});

Attr () callback function

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

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

Instance

The Code is 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.