Plugins


Plugins

A plugin piece of code written in a standard JavaScript file. These files provide useful jQuery methods that can be used and jQuery library methods.

How to use plugins

We insert a plugin file that closely resembles a jQuery library file in the document to make plugin methods available to us.

We have to make sure it appears in the back of the main jQuery source file and front of our custom JavaScript code.

Following is an example showing how to install the plugin jquery.plug-in.js -

<html> <head> <title> jQuery example </title> <script type = "text / javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script src = "jquery.plug-in.js" type = "text / javascript"> </script> <script src = "custom.js" type = "text / javascript"> </script> <script type = "text / javascript" language = "javascript"> $ (document). (function () { ....... your custom code ..... }); </script> </head> <body> ............................. </body> </html>

How to create a plug-in

This is very easy to write your plugin. The following is a syntax for building a path -

jQuery.fn.methodName = methodDefinition;

Here methodNameM is the name of the new method, and method definition is the definition of the actual method.

The following jQuery team recommended guide -

In the end, any path or function you paste should be semicolon (;).
Your method should return a jQuery item unless the specification is otherwise specified.

You should use this.each to scale over the current set of compatible items - it produces clean and consistent code that way. 4.

Start the file name with jquery, follow that with the plugin's name, and end with .js. Always attach the plugin to jQuery directly instead of $, so users can use the custom alias in the noConflict () way.

For example, if we are writing a plugin that we want to remove as debugs, our JavaScript file name for this plugin is -

jquery.debug.js

Use of jquery. Start eliminates any possible word conflicts with files for use with other libraries.