A. Z.
A. Z.

Reputation: 736

jQuery. How to stop repeated action once it happened?

I have an action that happens every 1 second:

(function(){
  $('.testme').jClever();
  setTimeout(arguments.callee, 1000);
})()

How can I stop it once it happened?

UPDATED: .testme comes from xmlhttpPost action and I can't get it work other way.

Upvotes: 0

Views: 126

Answers (1)

JK.
JK.

Reputation: 21834

You have to use clearTimeout() to stop setTimeout(), eg:

var clr = null;
(function(){
  $('.testme').jClever();
  clr = setTimeout(arguments.callee, 1000);
})()

// assuming that arguments.callee is a function named foo
function foo() {
    clearTimeout(clr);
}

Upvotes: 1

Related Questions