jQuery: exposing plugin's methods and properties

by Charlie Vaughan

HTML

<div id="test"></div>

JavaScript

(function($) {

	var pluginName = 'twoColumn';

    $.fn.plugin = function(options) {
    
        options = $.extend({
            test: 'Test'
        }, options);
        
        $.fn.plugin.method = function(text) {
            return '<strong>' + text + '</strong>';
        };
        
        $.fn.plugin.settings = options;

        return this.each(function() {
            var $element = $(this);
            $element.html($.fn.plugin.method(options.test));

        });
    };
})(jQuery);

$('#test').plugin();
alert($('#test').plugin.method('Foo'));
alert($('#test').plugin.settings.test);
alert(pluginName);