In jQuery code below a counter is started with start button and stopped using a stop button. Code works as expected but if you click the start button multiple time, then the rate of increment increases, I am more interested in knowing why this happen rather than the fix but that's fine too.
<style>
#count{
box-sizing:border-box;
height: 100px;
width: 100px;
padding: 30px;
margin-bottom: 30px;
background-color: red;
font-size: 40px;
color: white; }
</style>
HTML
<div id="count"></div>
<button id="stop">Stop Counter</button>
<button id="start">Start Counter</button>
jQuery
<script>
var eID;
var $t = $('#count');
$t.text('0');
$('#start').click(function() {
eID = window.setInterval(function(){
curr = $t.text();
new_count = parseInt(curr) + 1;
$t.text(new_count + '');
},1000);
console.log(eID);
});
$('#stop').click(function (){
window.clearTimeout(eID)
});
</script>
Thanks
bt