Milad Rahimi
Milad Rahimi

Reputation: 3834

How to make a jQuery plugin without selector?

How to make a jQuery plugin which needs some methods but doesn't need a selector like the following example?

$.plugin.method(param);

Upvotes: 1

Views: 577

Answers (1)

Milad Rahimi
Milad Rahimi

Reputation: 3834

Finally found the answer,

// jQuery Plugin Syntax
(function ($) {
    $.plugin = {
        method: function(param) {
            alert(param);
        };
    };
}(jQuery));

Now you can call it this way:

$.plugin.method("Hello World!");

Upvotes: 3

Related Questions