I've been trying to get my head around an approach to doing this for a while. Maybe I'm missing something.....
Say I have the plugin pattern:
(function($){
$.fn.myPlugin = function(options){
var bindEvents = function(elem){
// Bind the events here.
// EDIT
// My first first thought would be to pass the element to the method
// but what you are doing here is actually just bind the event to existing
// elements and not allowing for ajax added events.
$(document.body).on("click", $(elem), function(event){
// Do your thang....
});
};
return this.each(function(){
bindEvents(this);
});
};
}(jQuery||_jQuery));
How do I go about binding the events I want to objects using the $.on()
function so I can handle any dom element loaded via an Ajax request?
EDIT
To clarify what I mean by this I've added a few more comments to my code.