Although there are some examples about this on the web, it does not seem to work correctly. I can\'t figure out the problem.
I have this simple html
Had a similar problem, I propose this solution althought is not supported in IE 10 and under.
Given
The Javascript standard defines a property called dataset to update data-example-update.
document.getElementById('example').dataset.exampleUpdate = 2;
Note: use camel case notation to access the correct data attribute.
Source: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes