Talking about how JavaScript reads Custom Attributes of DOM objects (TAGS). DOM objects are a basic element for Javascript. Generally, JavaScript will always operate on them. We can easily add custom attributes to it, such:
var test = document.getElementById("test"); test.adang = "adang"; alert(test.adang);
We will find that an attribute named adang has been added to the DOM element whose id is test, and this attribute can be called in js. I often use this method when writing JavaScript, so that I can easily add some special data to a dom object. The DOM object is like a very useful container, you can put a pile of data in it.
Another question arises: can these attributes be added to js? Can they be added to tags like flex? In fact, attributes such as id and src can be added to js or tags. js can both obtain data. Here we need to say that the class is special. The label uses the class, but the class is used for calling in js.
Attributes supported by html such as id, title, and src can be set in tags and accessed by js. So what if it is a custom attribute like adang in my above example? Can DOM be accessed? I did an experiment as follows:
New document