Simply:
(function($){
$.fn.plugin = function()
{
// results in error
// when called like
// $.plugin();
}
})(jQuery);
The error is (copied from Chrome console):
Uncaught TypeError: Object function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
} has no method 'plugin'
What rules I have to follow in order to make my plugin work without the element selection?
Simply assign the function directly to $.plugin:
(function($){
$.plugin = function()
{
// ...
}
})(jQuery);
Of course this won't refer to selected elements anymore, but to jQuery itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With