Open In App

jQuery Plugins Introduction

Plugins are the section of code and these codes are written in a JavaScript file. These JavaScript files are used to provide jQuery methods that work together with jQuery library methods.

You can download jQuery plug-in from https://jquery.com/plugins



How to create a jQuery plugin with methods: In Jquery Plug-in is a code that is needed in a standard javascript file. Plugins help in providing different methods that can be used with different jquery library methods.

pNote: Where .methodname is the name of a method and
methoddefinition defines a method



Example: Here is a plug-in example.




jQuery.fn.alertMethod = function() {
   return this.each(function() {
      alert('GeeksforGeeks in "' + $(this).prop("tagName") + '"tag');
   });
};




<html>
   <head>
          
      <script type = "text/javascript" 
         src
      </script>
          
      <script src = "alert.js" type = "text/javascript">
      </script>
  
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("p").alertMethod();
         });
      </script
   </head>
      
   <body>
        
<p>GeeksforGeeks</p>
  
   </body>
</html>

Output:

How to check if a jQuery plugin is loaded:

npm install -g browser-sync

Complete Reference:


Article Tags :