- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a custom jQuery plugin?
To create a jQuery plugin, first create a file named jquery-demoplugin.js with the following code. This is our plugin code. Here, demoplugin is the name of our plugin. You can add any name to your custom plugin −
(function ( $ ) { $.fn.demoplugin = function( options ) { var web = $.extend({ name: 'example' }, options ); return this.append('Website: ' + web.name + '.com'); }; }( jQuery ));
Now, to load it, add to the HTML file, new.html −
<html> <head> <script src=" https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="jquery-demoplugin.js"></script> <script> $( document ).ready(function() { $( '#content ).demoplugin(); }); </script> </head> <body> <div id="content"></div> </body> </html>
- Related Articles
- How to create a custom jQuery Plugin?
- How to call a jQuery plugin function outside the plugin?
- How to call a jQuery plugin without specifying any elements?
- How to call a function inside a jQuery plugin from outside?
- How to implement custom events in jQuery?
- HTML5 video not working with jquery bxSlider plugin on iPad
- I want to create a custom tag in JSP. How to write a custom tag in JSP?
- How to get the value of custom attribute in jQuery?
- How to use jQuery selectors on custom data attributes using HTML5?
- How to write a valid MySQL query and update with a custom variable?
- How to write a jQuery selector for the label of a checkbox?
- How to write a custom adapter for my list view on Android using Kotlin?
- How to write a jQuery selector to find links with # in href attribute?
- How to implement a custom Python Exception with custom message?
- How to write custom Python Exceptions with Error Codes and Error Messages?

Advertisements