best way to set an intervalid so I can access later
I have an interval being set in my plugin. when I want to destroy the plugin I will need to be able to clear the interval.
What would be the best way to access the id?
- function($) {
- $.fn.myPlugin = function(options) {
- if (options == 'destroy') {
- // Want to destroy the interval timer here.
- // But how can I access it?
- return;
- }
- return this.each(function() {
- timer = setInterval(function() { foo();}, 1000);
- });
- function foo() {
- // Do some magic
- }
- };
- })(jQuery);