Permalink
Browse files

setInterval will clear itself when element removed

setInterval will clear itself when element is removed from the DOM.
  • Loading branch information...
1 parent 2877ea8 commit 63ab5d0325ec7566c9c222449efe95ac65940f1a @scotthovestadt committed Nov 15, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 jquery.timeago.js
View
@@ -113,7 +113,14 @@
var $s = $t.settings;
if ($s.refreshMillis > 0) {
- setInterval(function() { self.each(refresh); }, $s.refreshMillis);
+ var intervalID = setInterval(function() {
+ // Do not continue refresh if the element is no longer attached to the DOM.
+ if(self.parents(':last').is('html') == false) {
+ clearInterval(intervalID);
+ } else {
+ self.each(refresh);
+ }
+ }, $s.refreshMillis);
}
return self;
};

0 comments on commit 63ab5d0

Please sign in to comment.