Declare variable to assign value returned from setInterval(...) and pass the assigned variable to clearInterval();
e.g.
var timer, intervalInSec = 2;
timer = setInterval(func, intervalInSec*1000, 30 ); // third parameter is argument to called function 'func'
function func(param){
console.log(param);
}
// Anywhere you've access to timer declared above call clearInterval
$('.htmlelement').click( function(){ // any event you want
clearInterval(timer);// Stops or does the work
});