I have red many articles about writing object oriented javascript code and developing jQuery plugin, so far so good, I understand how they work and I can create my own plugins.
But, there is one problem with all the articles ( even with official plugin authoring guide - http://docs.jquery.com/Plugins/Authoring ) - these all patterns don`t support "live".
Let`s take for example this pattern - http://www.virgentech.com/blog/2009/10/building-object-oriented-jquery-plugin.html
$.fn.myplugin = function(options)
{
return this.each(function()
{
var element = $(this);
// Return early if this element already has a plugin instance
if (element.data('myplugin')) return;
// pass options to plugin constructor
var myplugin = new MyPlugin(this, options);
// Store plugin object in this element's data
element.data('myplugin', myplugin);
});
};
There will be created new "MyPlugin" instance on each jQuery matching object.
How to change it (if it`s posible) so it would work on elements that are added in the future?
Thanks