HTML5 custom Data properties, that is, data-* custom attributes---notes.

Source: Internet
Author: User

HTML5 custom Data properties, that is, data-* custom properties.

For example

<div  data-last-value= "data-hidden=" true "data-options= ' {" name ":" John "} ' ></div>


There are three ways to access and modify data:
1. Use the GetAttribute SetAttribute method such as Div.getattribute ("Data-last-value")
2. Using the DataSet property
Returns a collection
Div.dataset-Domstringmap {options: "{\" name\ ": \" john\ "}", Hidden: "True", Lastvalue: "43"}
can access, add, delete

Div.dataset.hidden div.dataset.newAttr = "123" Delete Div.dataset.hidden
3. Using the data method of jquery
. Data (key, value)
. Data (key, value)
. Data (obj)--Set multiple key-value pairs
. Data (Key)
. Data (Key)
. Data ()-Returns a collection
jquery is very special, it will automatically convert the return value string to the corresponding data type.
such as the $ ("div") above. Data ()--+ options: {"name": "John"}, Hidden:true, lastvalue:43}

Note:For the DataSet property and the data method of jquery: The Data-property name if it contains a hyphen, for example: Data-last-value, the hyphen is stripped and converted to a camel-named name, the preceding property name is converted to: Lastvalue.

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.