/ ACCESSIBILITY, FRONT-END

How to set and get data attributes in HTML?

Question

There is a div with an attribute data-value = "10".

Does there is anyway to get and update the data-value value?

Answer

<div id="mydiv" data-value="10"></div>
var a = $('#mydiv').data('myval'); //getter

$('#mydiv').data('myval',20); //setter

Live Demo

Reference


This is the end of post