[jQuery] jQuery Kinda Plugin: every

[jQuery] jQuery Kinda Plugin: every

I don't know if this exists already but I needed this and assumed it
didn't and wrote it myself. Essentially it lets you do something to an
element every given time interval.
jQuery.fn.every = function(interval,fn) {
return this.each(function() {
var self = this;
window.setInterval(function() { fn.call(self) },interval);
});
};
I used it to get a millisecond amount display every so often to produce
a live updated element. It's mostly for live clock updating (and I
suppose it could be useful to implement polling) but I'm sure the
creative among you could find some other purpose for it.
Example:
// Display the current time updated every 500 ms
$("p.display").every(500,function() {
$(this).html(new Date());
});
-blair
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/