mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
8d7ec1a81c
This function converts text from camelCase to dash-style and prepends "data-" to string.
37 lines
890 B
HTML
37 lines
890 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
|
|
<div id="a" data-a="1" data-b="abc" data-abc-cd="1234"></div>
|
|
|
|
<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');
|
|
console.assert(div.dataset.abc === undefined, 'undefined');
|
|
|
|
delete(div.dataset.b);
|
|
console.assert(div.dataset.b === undefined, 'undefined because deleted');
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
console.error('element.dataset.html');
|
|
myFunction();
|
|
console.exit();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|