How to create a custom jQuery Plugin?

jQueryWeb DevelopmentFront End Technology

To create a jQuery plugin, firstly create a file named jquery-myplugin.js with the following code. This is our plugin code. Here, myplugin is the name of our plugin.

(function ( $ ) {
   $.fn.myplugin = function( options ) {
      var web = $.extend({
         name: 'tutorialspoint'
      }, options );
      return this.append('Website: ' + + '.com');
}( jQuery ));

Now, to load it, add to the HTML file, new.html:

<script src=""></script>
<script src="jquery-myplugin.js"></script>
$(document).ready(function() {
<div id="myclass"></div>

Run the above code and you can see the text is visible, which shows your custom plugin is working correctly.

Published on 06-Dec-2017 22:49:33