SlideShare a Scribd company logo
JQuery Plugin Development
Faruk Hossen
What is JQuery
➢ JQuery is a Javascript Library.
➢ The jQuery library contains the following features:
○ HTML/DOM manipulation
○ CSS manipulation
○ HTML event methods
○ Effects and animations
○ AJAX
○ Utilities
➢jQuery is a javascript object.
var jQuery = function( ) {
//object properties go here.
};
JQuery Object
➢ ‘$’ is shorthand for jQuery
➢ When we call the $() function and pass a selector to it,
we create a new object
$( document );
$(“div.menu”);
$(“div.menu”).click(function(){
$(this).find(“ul”).show();
}
JQuery Object
➢Javascript prototype object is
■ $.fn or
■ jQuery.fn
JQuery Prototype Object
➢ All objects have a prototype property.
➢ The JavaScript prototype property also allows you to add new methods to
an existing prototype.
➢ It is simply an object from which other objects can inherit properties
What is prototype of an object in js
function person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
person.prototype.name = function() {
return this.firstName + " " + this.lastName
};
var myFather = new person("John", "Doe", 50, "blue");
console.log(myFather.name());
What is prototype of an object in js
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function () {
alert(this.name + " says hello");
};
var james = new Person("James");
james.sayHello(); // Alerts "James says hello"
What is prototype of an object in js
jQuery.fn = jQuery.prototype.
from jquery source code:
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
// ...
return this;
}
// jQuery API methods
}
What is $.fn
➢ In object-oriented programming languages, this (or self) is a keyword
which can be used in instance methods to refer to the object
➢ There are really two main contexts of 'this' in jQuery.
○ ‘this’ first refers to a DOM element
○ ‘this’ refers to a jQuery object.
What is ‘this’
$( "p" ).click(function() {
$( this ).slideUp();//is it wrong?
this.slideUp() //is it wrong?
});
What is ‘this’ (continues…)
jQuery.fn.newTarget = function() {
this.hide(); //will it show error?
$(this).hide(); //will it show error?
}
$(‘p’).newTarget();
What is ‘this’ (continues…)
What is JQuery Plugin
➢ A jQuery plugin is simply a new method that we use to extend jQuery's
prototype object.
➢ By extending the prototype object you enable all jQuery objects to inherit
any methods that you add.
➢ As established, whenever you call jQuery() you're creating a new jQuery
object, with all of jQuery's methods inherited.
➢Portability
➢Time
Why JQuery Plugin
➢ Packaging a common function within a jQuery plugin will normally make
it more portable.
➢ Doing so allows you to easily integrate the plugin into any number of
projects within a short amount of time.
➢ Reusability, another buzz word, comes hand in hand with this.
portability
➢ It will save you (and your users) time.
➢ The time it takes to develop a robust plugin is clearly worth it when you
consider what it enables.
Time
➢ jQuery allows methods to be added to its library.
➢ When called, these methods are passed the jQuery object within the
JavaScript ‘this’ object.
➢ The DOM nodes can be manipulated as required
➢ The method should return ‘this’ so other functions can be chained.
How JQuery Plugin Works
1.plugin function
2.options
3.callback
4.ability to chain.
JQuery Plugin Components
$( "#clickme" ).click(function() {
$( "#book" ).animate({
opacity: 0.25,
left: "+=50",
height: "toggle"
}, 5000, function() {
// Animation complete.
});
});
JQuery Plugin Components
(function($) {
jQuery.fn.hightlight = function(options) { ... };
})(jQuery);
(function($) {
$.fn.hightlight = function(options) { ... };
})(jQuery);
Note: Using ‘jQuery’ rather than ‘$’ ensures there are no conflicts with other
JavaScript libraries.
JQuery Plugin Declaration
//default settings
(function($) {
$.fn.highlight = function(options) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
};
})(jQuery);
Options in Plugin
1. $(“p”).highlight(); //uses default settings.
1. $(“p”).highlight(//uses color:white,background:yellow
‘color’:’white’;
);
1. $(“p”).highlight(//uses color:white,background:red
‘color’:’white’
‘background’:’red’;
);
Passing Options
(function($) {
$.fn.highlight = function(options,callback) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
callback.call(this);
};
})(jQuery);
Callback function
1. $(“p”).highlight(//uses color:white,background:red
{
‘color’:’white’
‘background’:’red’
},function(){
//execute after complete
}
);
Callback function
(function($) {
$.fn.highlight = function(options,callback) {
var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’};
$.extend(settings,options);
callback.call(this);
return this; // it is for chaining
};
})(jQuery);
Ability to chain
Ability to chain
THANKS

More Related Content

PDF
Introducing jQuery
PDF
JQuery plugin development fundamentals
PDF
Jquery plugin development
ODP
Jquery Plugin
PDF
Dojo Confessions
PDF
Functionality Focused Code Organization
PDF
Building Large jQuery Applications
PDF
Mulberry: A Mobile App Development Toolkit
Introducing jQuery
JQuery plugin development fundamentals
Jquery plugin development
Jquery Plugin
Dojo Confessions
Functionality Focused Code Organization
Building Large jQuery Applications
Mulberry: A Mobile App Development Toolkit

What's hot (20)

PDF
jQuery secrets
KEY
jrubykaigi2010-lt-rubeus
PPTX
Lecture 6: Client Side Programming 2
PPTX
Basics of j query
PDF
A New Baseline for Front-End Devs
PPTX
Lecture 5: Client Side Programming 1
PPT
Kick start with j query
PPT
PDF
Beyond the DOM: Sane Structure for JS Apps
PDF
Using Objects to Organize your jQuery Code
ODP
JQuery introduction
PPTX
J Query The Write Less Do More Javascript Library
PDF
Learning jQuery in 30 minutes
PPT
jQuery 1.7 Events
PDF
How Kris Writes Symfony Apps
PPTX
jQuery Data Manipulate API - A source code dissecting journey
PPTX
How to increase Performance of Web Application using JQuery
PDF
Your Entity, Your Code
jQuery secrets
jrubykaigi2010-lt-rubeus
Lecture 6: Client Side Programming 2
Basics of j query
A New Baseline for Front-End Devs
Lecture 5: Client Side Programming 1
Kick start with j query
Beyond the DOM: Sane Structure for JS Apps
Using Objects to Organize your jQuery Code
JQuery introduction
J Query The Write Less Do More Javascript Library
Learning jQuery in 30 minutes
jQuery 1.7 Events
How Kris Writes Symfony Apps
jQuery Data Manipulate API - A source code dissecting journey
How to increase Performance of Web Application using JQuery
Your Entity, Your Code
Ad

Viewers also liked (6)

PPTX
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
ODP
Jquery Plugin
PPT
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
KEY
jQuery Plugin Creation
PDF
Oop unit 05 một số kỹ thuật java nâng cao
PDF
Artificial intelligence ai l1-gioi thieu
Box Sạc Dự Phòng - Công Cụ Cần Có Dành Cho Dân Phượt
Jquery Plugin
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
jQuery Plugin Creation
Oop unit 05 một số kỹ thuật java nâng cao
Artificial intelligence ai l1-gioi thieu
Ad

Similar to Jquery plugin development (20)

PPT
PPTX
Jqueryppt (1)
PPT
J query presentation
PPT
J query presentation
PPT
JS Libraries and jQuery Overview
PPTX
J query resh
PPTX
Upstate CSCI 450 jQuery
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
PPTX
JQuery_and_Ajax.pptx
PPT
Intro to jQuery - LUGOR - Part 1
PPT
jQuery For Developers Stack Overflow Dev Days Toronto
PDF
jQuery Interview Questions By ScholarHat.pdf
PPTX
Starting with jQuery
PDF
jQuery in 15 minutes
PDF
jQuery (DrupalCamp Toronto)
KEY
Jquery Fundamentals
PPT
JQuery introduction
KEY
Everything You Need to Know in Order to Start Using jQuery
Jqueryppt (1)
J query presentation
J query presentation
JS Libraries and jQuery Overview
J query resh
Upstate CSCI 450 jQuery
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
JQuery_and_Ajax.pptx
Intro to jQuery - LUGOR - Part 1
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery Interview Questions By ScholarHat.pdf
Starting with jQuery
jQuery in 15 minutes
jQuery (DrupalCamp Toronto)
Jquery Fundamentals
JQuery introduction
Everything You Need to Know in Order to Start Using jQuery

Recently uploaded (20)

PPTX
Glazing at Facade, functions, types of glazing
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
PPTX
TE-AI-Unit VI notes using planning model
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
Queuing formulas to evaluate throughputs and servers
PDF
Introduction to Data Science: data science process
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
AgentX UiPath Community Webinar series - Delhi
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Glazing at Facade, functions, types of glazing
Chapter 6 Design in software Engineeing.ppt
July 2025: Top 10 Read Articles Advanced Information Technology
TE-AI-Unit VI notes using planning model
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
CH1 Production IntroductoryConcepts.pptx
“Next-Gen AI: Trends Reshaping Our World”
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Queuing formulas to evaluate throughputs and servers
Introduction to Data Science: data science process
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
AgentX UiPath Community Webinar series - Delhi
Model Code of Practice - Construction Work - 21102022 .pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...

Jquery plugin development

  • 2. What is JQuery ➢ JQuery is a Javascript Library. ➢ The jQuery library contains the following features: ○ HTML/DOM manipulation ○ CSS manipulation ○ HTML event methods ○ Effects and animations ○ AJAX ○ Utilities
  • 3. ➢jQuery is a javascript object. var jQuery = function( ) { //object properties go here. }; JQuery Object
  • 4. ➢ ‘$’ is shorthand for jQuery ➢ When we call the $() function and pass a selector to it, we create a new object $( document ); $(“div.menu”); $(“div.menu”).click(function(){ $(this).find(“ul”).show(); } JQuery Object
  • 5. ➢Javascript prototype object is ■ $.fn or ■ jQuery.fn JQuery Prototype Object
  • 6. ➢ All objects have a prototype property. ➢ The JavaScript prototype property also allows you to add new methods to an existing prototype. ➢ It is simply an object from which other objects can inherit properties What is prototype of an object in js
  • 7. function person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; } person.prototype.name = function() { return this.firstName + " " + this.lastName }; var myFather = new person("John", "Doe", 50, "blue"); console.log(myFather.name()); What is prototype of an object in js
  • 8. function Person(name) { this.name = name; } Person.prototype.sayHello = function () { alert(this.name + " says hello"); }; var james = new Person("James"); james.sayHello(); // Alerts "James says hello" What is prototype of an object in js
  • 9. jQuery.fn = jQuery.prototype. from jquery source code: jQuery.fn = jQuery.prototype = { init: function( selector, context ) { // ... return this; } // jQuery API methods } What is $.fn
  • 10. ➢ In object-oriented programming languages, this (or self) is a keyword which can be used in instance methods to refer to the object ➢ There are really two main contexts of 'this' in jQuery. ○ ‘this’ first refers to a DOM element ○ ‘this’ refers to a jQuery object. What is ‘this’
  • 11. $( "p" ).click(function() { $( this ).slideUp();//is it wrong? this.slideUp() //is it wrong? }); What is ‘this’ (continues…)
  • 12. jQuery.fn.newTarget = function() { this.hide(); //will it show error? $(this).hide(); //will it show error? } $(‘p’).newTarget(); What is ‘this’ (continues…)
  • 13. What is JQuery Plugin ➢ A jQuery plugin is simply a new method that we use to extend jQuery's prototype object. ➢ By extending the prototype object you enable all jQuery objects to inherit any methods that you add. ➢ As established, whenever you call jQuery() you're creating a new jQuery object, with all of jQuery's methods inherited.
  • 15. ➢ Packaging a common function within a jQuery plugin will normally make it more portable. ➢ Doing so allows you to easily integrate the plugin into any number of projects within a short amount of time. ➢ Reusability, another buzz word, comes hand in hand with this. portability
  • 16. ➢ It will save you (and your users) time. ➢ The time it takes to develop a robust plugin is clearly worth it when you consider what it enables. Time
  • 17. ➢ jQuery allows methods to be added to its library. ➢ When called, these methods are passed the jQuery object within the JavaScript ‘this’ object. ➢ The DOM nodes can be manipulated as required ➢ The method should return ‘this’ so other functions can be chained. How JQuery Plugin Works
  • 18. 1.plugin function 2.options 3.callback 4.ability to chain. JQuery Plugin Components
  • 19. $( "#clickme" ).click(function() { $( "#book" ).animate({ opacity: 0.25, left: "+=50", height: "toggle" }, 5000, function() { // Animation complete. }); }); JQuery Plugin Components
  • 20. (function($) { jQuery.fn.hightlight = function(options) { ... }; })(jQuery); (function($) { $.fn.hightlight = function(options) { ... }; })(jQuery); Note: Using ‘jQuery’ rather than ‘$’ ensures there are no conflicts with other JavaScript libraries. JQuery Plugin Declaration
  • 21. //default settings (function($) { $.fn.highlight = function(options) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); }; })(jQuery); Options in Plugin
  • 22. 1. $(“p”).highlight(); //uses default settings. 1. $(“p”).highlight(//uses color:white,background:yellow ‘color’:’white’; ); 1. $(“p”).highlight(//uses color:white,background:red ‘color’:’white’ ‘background’:’red’; ); Passing Options
  • 23. (function($) { $.fn.highlight = function(options,callback) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); callback.call(this); }; })(jQuery); Callback function
  • 25. (function($) { $.fn.highlight = function(options,callback) { var settings = {‘highlight-color’:’white’,’highlight-background’:’yellow’}; $.extend(settings,options); callback.call(this); return this; // it is for chaining }; })(jQuery); Ability to chain