Call inner function of jQuery-Plugin-function?

Posted by faileN on Stack Overflow See other posts from Stack Overflow or by faileN
Published on 2010-12-27T07:49:49Z Indexed on 2010/12/27 7:53 UTC
Read the original article Hit count: 138

Filed under:
|
|

Hello Everyone,

I've written an jQuery-Plugin, which I want to use as Object. So I declared some functions within the plugin, which I want to call from any other location, just like an object with methods. Is that even possible?

To keep it simple:

(function( $ ){
    $.fn.myPlugin = function(){
        // Here I want methods...
        function foo()
        {
             // do something...
        }
    }
})(jQuery);

Then I want to call the inner function from outside the plugin like:

$.myPlugin.foo();

But that doesn't seem to work. So is it even possible? Or are there any other solutions? I don't want to use an normal unrelated jQuery-Class for this purpose. Because this plugin should work together with some other jQuery-Plugins.

Thank you

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery