Reputation: 3711
I've created a nice jQuery plugin that looks something like this:
;(function($, window, document){
// MyPlugin stuff
$.fn.myPlugin = function(){
new MyPlugin(this).init();
}
)(jQuery, window, document);
Works great when called on an element like this: $('.something').myPlugin();
but I'd like to also be able to do this $.myPlugin.somemethod()
(use it without an jQuery selector).
How would I do that? Thanks!
Upvotes: 0
Views: 402
Reputation: 318182
By not attaching it to jQuery's prototype (fn), but as a property of jQuery
instead, or in addition to the plugin etc :
$.myPlugin = {
somemethod : function() {
alert('stuff');
}
}
Upvotes: 2