jquery plugin pattern using jquery.data

Posted by web_dev on Stack Overflow See other posts from Stack Overflow or by web_dev
Published on 2012-12-06T17:01:47Z Indexed on 2012/12/06 17:03 UTC
Read the original article Hit count: 142

Filed under:

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 ));
            }
        });
    };

© Stack Overflow or respective owner

Related posts about jQuery