2024-06-28 08:14:24 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
|
2024-06-29 03:42:48 -04:00
|
|
|
<div id="a" data-a="1" data-b="abc" data-abc-cd="1234"></div>
|
2024-06-28 08:14:24 -04:00
|
|
|
|
|
|
|
<button onclick="myFunction()">Try it</button>
|
|
|
|
|
|
|
|
<p id="demo"></p>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function myFunction() {
|
|
|
|
var div = document.getElementById('a');
|
|
|
|
console.assert(div.dataset.b === 'abc', 'abc');
|
|
|
|
div.dataset.b = '123';
|
|
|
|
console.assert(div.dataset.b === '123', '123');
|
2024-06-28 10:42:11 -04:00
|
|
|
console.assert(div.dataset.abc === undefined, 'undefined');
|
|
|
|
|
|
|
|
delete(div.dataset.b);
|
|
|
|
console.assert(div.dataset.b === undefined, 'undefined because deleted');
|
2024-06-29 03:42:48 -04:00
|
|
|
|
|
|
|
console.assert(div.dataset.abcCd === '1234', 'camelCase');
|
|
|
|
div.dataset.abcCd = '2345';
|
|
|
|
console.assert(div.dataset.abcCd === '2345', 'camelCase set');
|
|
|
|
delete(div.dataset.abcCd);
|
|
|
|
console.assert(div.dataset.abcCd === undefined, 'undefined after deletion');
|
|
|
|
|
2024-06-28 08:14:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
console.error('element.dataset.html');
|
|
|
|
myFunction();
|
|
|
|
console.exit();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|