Can't update data-attribute value

后端 未结 9 1566
北海茫月
北海茫月 2020-11-27 17:11

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

         


        
9条回答
  •  伪装坚强ぢ
    2020-11-27 17:37

    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

提交回复
热议问题