Calling a jQuery plugin without specifying any elements

Viewed 14366

Say I have the following jQuery plugin:

$.fn.myPlugin = function () {
    //plugin code
}

Normally, you call a plugin on a certain number of elements, like such:

$("body").myPlugin();

Is there any way I can call my plugin without specifying an element?

I have tried calling it like such: $.myPlugin();, but that does not work.

What works is this: $().myPlugin();, but is that the correct way to invoke it?

3 Answers
Related