Html5 custom data attributes, that is, data-* Custom Attributes-notes ., Html5data-

Source: Internet
Author: User

Html5 custom data attributes, that is, data-* Custom Attributes-notes ., Html5data-

Html5 custom data attributes, that is, data-* Custom Attributes.

For example

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

 


There are three methods to access and modify data:
1. Use the getAttribute setAttribute method, for example, div. getAttribute ("data-last-value ")
2. Use dataset attributes
Returns a set.
Div. dataset --> DOMStringMap {options: "{\" name \ ": \" John \ "}", hidden: "true", lastValue: "43 "}
Accessible, add, or delete

Div. dataset. hidden div. dataset. newAttr = "123" delete div. dataset. hidden
3. Use jquery's data method
. Data (key, value)
. Data (key, value)
. Data (obj) --> set multiple key-value pairs
. Data (key)
. Data (key)
. Data () --> Returns a set
JQuery automatically converts the returned value string to the corresponding data type.
For example, the above $ ("div"). data () --> {options: {"name": "John"}, hidden: true, lastValue: 43}

Note:For the dataset attribute and the data method of jQuery: if the data-attribute name contains a hyphen, for example, data-last-value, the hyphen will be removed, and convert it to a camper name. The previous attribute name should be lastValue after conversion.


Question about custom attributes of html tags

Does not affect html js. You can write n attributes.
You only need JS to get its value through xxx. getAttribute ("your written attribute ").
 
A small question about the jQuery UI framework: Where are the custom attributes of the following HTML elements defined?

The components you used above should be in the pop-up box. These parameters are all customized by jquery ui. These parameters will be mentioned in the api documentation, www.jeasyui.com/documentation/index.php, you can find the "dialog" link in the left navigation bar and you will see the relevant parameters. These attributes are not described in detail, but they are used in the instance, in addition, it can be seen from the literal meaning what the specific role is.

Related Article

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.