jquery

Get and set attribute value jQuery

//GET ATTRIBUTE VALUE
$("div").attr("data-number");

//SET ATTRIBUTE VALUE
$("div").attr("data-number", "20");

.attr() method in jQuery is used to get and set attribute value to an HTML element. We are setting the "data-number" attribute value to "20" by using snippet code.

Was this helpful?