I am trying to write a jQuery plugin. For simplicity let's say that my code is
$.fn.myplugin = function() {
return this.each(function() {
$('a.mypluginToken').live('click', function(){})
}
}
As per above code every single time $('a').myplugin is called, a binding is done for 'click' event because of 'live'. I need that binding to be done only once and not for each element that invokes my plugin.
one solution is that after binding the click event I set a data on document saying 'binding_done'. And check for that data every single time. Even though that solution will work I am wondering if there is a better jQuery design pattern that I am missing.
Thanks.
I am using jQuery 1.4.2