I have a div with an attribute data-myval = "10". I want to update its value; wouldn’t it change if I use div.data('myval',20)? Do I need to use div.attr('data-myval','20') only?
Am I getting confused between HTML5 and jQuery? Please advise. Thanks!
EDIT: Updated div.data('myval')=20 to div.data('myval',20), but still the HTML is not updating.
HTML
JS
Demo
Reference
From the reference:
It should be noted that jQuery’s
data()doesn’t change thedataattribute in HTML.So, if you need to change the
dataattribute in HTML, you should use.attr()instead.HTML
jQuery:
See this demo