In the span loop, there is an initialized variable 'a' with the value '0'. https://jsfiddle.net/k99yoL10/1 at the event of a click this variable increases by 1. Can I make it so that when I click on the black span I reset the variable in the first span?
$('span').each(function(){ var a=0; $(this).click(function(){ alert(a); a++; }); }); span{ display:inline-block; width:70px; height:50px; background: red; } span:last-of-type{ background: #000; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span></span> <span></span>
data-attributes - teran