Is there a way to change the value of an html variable using jquery.
For instance,
<div id="smile" data-count="2"></div>
how would I change the variable data-count to 3 using jquery
Is there a way to change the value of an html variable using jquery.
For instance,
<div id="smile" data-count="2"></div>
how would I change the variable data-count to 3 using jquery
You can do:
$('#smile').data('count', 3);
or:
$('#smile').attr('data-count', 3);
You can store the data value in a variable and then increase it like this:
var data = parseInt($('#smile').attr('data-count'), 10);
$('#smile').attr('data-count', data+1);
$('#smile').data('count', 3); doesn't change the attribute of the element, it only updates jQuery's internal data storage.radix which is a number (from 2 to 36) that represents the numeral system to be used, i.e. 2 for binary, 10 for decimal, 16 for hexadecimal. You can used @Felix Kling reference link for more details about it.