I\'m a bit new to js and have been trying to figure out how to stop this function from running when I click on a button. I tried using clearInterval but I am not sure I am d
You need to give JavaScript a reference to the interval:
var t = setTimeout(function() { timer(counter + 1); }, 3000);
Then you can clear it like so:
$("#stop").click(function () { clearTimeout(t); });