I attempted to modify the data
attribute in my code snippet below.
After clicking on the square, the data
attribute should be incremented.
However, it appears that the incrementing is not happening as expected.
How can I resolve this issue?
Additionally, why did this problem occur in the first place?
Thank you for your help!
$("td").click(function() {
index=$(this).data('layer');
index+=1
$(this).attr('data-layer',index);
console.log(this);
});
td {
border:solid black 1px;
width:50px;
height:50px;
cursor:pointer;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td data-layer="0"></td>
</tr>
</table>