jquery plugin pattern using jquery.data
- by web_dev
I have seen this piece of code in jquery plugin patterns and the notes section mention that we could attach the plugin to the DOM element using the jQuery.data function. What I don't understand is how do I make use of this piece of code. Can somebody provide examples of how to use this functionality and explain its significance?
$.fn[pluginName] = function (options) {
return $Extend(this).each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin( this, options ));
}
});
};