jquery plugin syntax -


I am trying to create a jquery plugin, and I have the following options:

  1. $ Plugin_name (variable)

  2. $ (selector) .plugin_name (variable)

The first case is not required to apply the plugin to any element (it can create one for example), the second case is selected by the same plugin which element / s is selected

My The question is how do I specify within this plugin:

  if (not selected selector) {create an element} and {(for example) insert the match with the selector The variable  

You can use the jQuery.fn . MyPluginName = function () .... which work on jQuery objects.

jQuery For a standalone function in the namespace, you can simply JQuery.func_name = function () ... .

A test e:

  jQuery.fn.erase = function () {return.Each (function () {jQuery (this) .remove ();}) ; }; . Erase JQuery ("body"); JQuery.erase = Function (Element) {jQuery (Element) .rase (); }; JQuery.erase ("body"); // Exactly same result  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -