jquery - stop a function declared inside setInterval() using clearInterval() -
how stop function declared inside setinterval(), like
var start = function(){ setinterval(function(){//do something},3000) }; var stop = function() { clearinterval(start); }; $('button.start').click(function(){ start(); }); $('button.stop').click(function(){ stop(); });
but still not able stop setinterval function here. need little on that. thanks
declare variable interval
.
setinterval create id.
then assign setinterval
id inertval
variable .
if wanna stop setinterval
pass inertval
clearinterval
try
var interval; var start = function(){ interval=setinterval(function(){ //do },3000) }; var stop = function() { clearinterval(interval); };
Comments
Post a Comment