How to remove data-* attributes using HTML5 dataset
A rather simpler and straightforward approach:
const someElement = document.querySelector('...');
Object.keys(someElement.dataset).forEach(dataKey => {
delete someElement.dataset[dataKey];
});
Wouldn't 'delete' remove dataset element? E.g.:
<div id="a1" data-foo="bar">test</div>
<script>
var v = document.getElementById('a1');
alert(v.dataset.foo);
delete v.dataset.foo;
alert(v.dataset.foo);
</script>