While it's not very jQuery-like, timers lend themselves to registration. 
I would attach an object to window or a more permanently/easily available
object.  This way, you don't have to leave closures around just to keep
references to the timers, just so you can stop them later.

Also, if you're attaching the timer references to DOM objects, then I
think that you are opening the door to possible serious memory leakage. 
Clever, but perhaps dangerous.

- Brian


> And I just realized I should make it possible to stop the repeating
> function later on.
>
> Code:
> jQuery.fn.every = function(interval,fn) {
>     return this.each(function() {
>         var self = this;
>         this.$every = window.setInterval(function() { fn.call(self)
> },interval);
>     });
> };
>
> Example:
> // Display the current time updated every 500 ms
> $("p.display").every(500,function() {
>     $(this).html(new Date());
> });
>
> //... some point later in the code execution
> $("p.display").each(function() {
>     window.clearInterval(this.$every);
>     this.$every = null;
> });
>
> -blair
>
> Blair Mitchelmore wrote:
>> 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.
>>
>>
>> -blair
>>
>
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to