jquery's data () function and HTML5 's Data property

Source: Internet
Author: User

jquery's data () function and HTML5 's Data property:
A new custom Data property is added to the HTML5, which allows you to add any property that begins with "data-", which is no longer displayed on the page, does not affect any of the original layout effects, and is read-write, such as:

<div id= "Thediv" data-webname= "Ant Tribe" > Ant Tribe Welcome </div>

The above code is a simple example of using a custom data property.
You can use the data () function of jquery to read these properties with the following code:

var webname= jQuery ("#thediv"). Data (' WebName '); Console.log (webname);

The above code can output custom attribute values: "Ant Tribe".
You can use JSON-formatted data in custom properties, such as:

<id= "Thediv"  data-webaddress= ' {' address ': ' Shinan '} '> Ant Tribe welcome you </div>

You can also use the data () function of jquery and use the key of the JSON data to get the corresponding value, for example:

var address= $ ("#thediv"). Data (' WebName '). Address; Console.log (address);

More actions are not introduced here, specifically, you can refer to the data () method of jquery chapter.
Special Note:
In a non-HTML5 page or browser, you can still manipulate the "data-*" data using the. Data (obj) method.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8755

For more information, refer to: http://www.softwhy.com/jquery/

jquery's data () function and HTML5 's Data property

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.