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?