How to prevent a clicked function double fired (or fired multiple times)

I’ve a click function below. When you’re clicking on it it fired. If you click two times it fires two times, and so on and on until it crashes.

function log(msg) {document.getElementById('log').innerHTML = msg + '<br/>';}

var a = function() {
        var j = 0;
	setInterval(function() {
		log('A: ' + j++);

var b = document.getElementById('button');

b.addEventListener('click', a, false);

I don’t want to disable click. If a user clicks on the button I want it pause/stop then resume or refresh or something.

Thank you,

This will eventually make your browser crash just by clicking it enough over time as you’re never clearing the first and subsequent intervals, could you please explain how the logic should work as currently I’m not sure what you’re trying to do with the above code snippet.

Thanks for response. I want to refresh the function or pause/resume anytime I click on the button. I’ve no idea how to clear the first and subsequent interval. This is just an example of code I made it as simple as possible. But I thought it would be able to solve my more complex function if I have an idea how to do it.