(function($)
{
$.fn.myPlugin = function(options)
{
var _this;
var timer1;
var foo = function(n)
{
if (timer1 != null) return; // in action
timer1 = setInterval("bar("+n+")", 500);
};
var bar = function(n)
{
...
if ( ... ) clearInterval(timer1);
};
return this.each(function()
{
_this = $(this);
_this.bind("click", function(){ foo(10); });
});
}
})(jQuery);
This doesn’t work because “bar is not defined.”
Instead of a string, you need to pass a function which directly references
bar, so instead of this:Do this:
You can see this working here
Also, you need to accept questions to get any future answers, you do this by clicking the checkmark beside the answer that helped you resolve the issue. It gives you rep, the answerer rep, and helps the next googler find the appropriate answer faster.