Developing a jQuery plugin that returns a given object, instead of jQuery object itself!

Posted by mehdi5275 on Stack Overflow See other posts from Stack Overflow or by mehdi5275
Published on 2010-04-01T17:31:21Z Indexed on 2010/04/01 17:33 UTC
Read the original article Hit count: 233

Hi, Consider the following base code:

(function($) {
    $.fn.myPlugin = function(settings) {
        return this.each(function() {
            //whatever
        });
    };
});

The plugin returns a jQuery object. The question is how am I supposed to write a plugin that returns a custom object so that I can do something like this:

var api = $('div.myelement').myPlugin();
api.onMyEventName(function(e, whateverParam) {
    //whatever
});

It'd be highly appreciated if you could write some lines of code that describes me how to do that, how to call the onMyEventName function on a custom api object...

Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-plugins