I want to use a watcher on a dataset. This is my code:
Html:
<div id='my-hidden-content' data-is-collapsed='true'>My hidden content</div>
Javascript:
document.getElementById('my-hidden-content').dataset.watch('isCollapsed', function(id, oldval, newval) {
console.log('Collapsed changed', id, oldval, newval)
});
My console puts out this error:
'Uncaught TypeError: document.getElementById(...).dataset.watch is not a function'
How could I use a watcher on a dataset without using any frameworks?
*Edit I'm try to build a component which could be implementend into every framework and adding classes to it's node if the value of the dataset changes.