What's the difference with html5 data-* custom attributes.
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-05 09:55:59
0
3
723

<li data-animal="fish">Salmon</li> and<li animal="fish">Salmon</li> New What is the difference between html5 custom attributes and ordinary defined attributes? They are both defined attributes.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
小葫芦

1. Normative
2. Have a dedicated interface dataset

为情所困

As mentioned above, the access methods of properties are different.

<li data-animal="fish" id="hello">Salmon</li>
<li animal="fish" id="hi">Salmon</li>
var hello = document.getElementById("hello");
var hi = document.getElementById("hi");

// 获取id为hello的元素的data-animal属性
console.log(hello.getAttribute("data-animal")); // "fish"
console.log(hello.dataset.animal); // "fish"

// 获取id为hi的元素的animal属性
console.log(hi.getAttribute("animal")); // "fish"
ringa_lee

In the IDE, no warning will be reported if there is a data- prefix.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!