HTML5 Custom Attribute Data-* property name must be lowercase?

Source: Internet
Author: User

Recently learning JavaScript, the reference book is the third edition of JavaScript Advanced Programming, which gives an example when introducing custom element attributes, as follows:
<div id= "mydiv" data-appid= "12345" data-myname= "Nicholas" ></div>

Ideally you can access the data through MyDiv.dataset.appId, MyDiv.dataset.myname, but in the actual test found appId value of undefined, online check, said HTML5 custom properties can not contain uppercase letters, Is this constraint unreasonable?

If I remember correctly, all attribute names should be lowercase.

Oh, forget to say, if you want to visit with AppId, you should write Data-app-id.

No, no responsibility, guess Data-app-id is appId in the dataset.

All label attributes, not case sensitive, are lowercase. The dataset automatically converts-to hump. Similar to CSS in the style properties, such as Background-color, in JS corresponding to the backgroundcolor. Of course you will find that if you are determined to write Element.style.backgroundColor element.style[' Background-color ', in chrome can also be effective, but did not verify that it is not the standard Behavior. In short follow the specification is, with Data-app-id, data-my-name as attributes, JS directly ele.dataset.appId access. In addition to some attribute such as IDs, other non-datasets can only be accessed by calling SetAttribute or GetAttribute. And, as previously mentioned, attribute are ignored and case-sensitive. You have to look at the website for many years, and you will find all the tags in full capitalization.

HTML5 Custom Attribute Data-* property name must be lowercase?

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.