SlideShare a Scribd company logo
2
Most read
4
Most read
7
Most read
By: Dominic Arrojado
What is jQuery?
jQuery is a fast, small, and feature-rich JavaScript library. It makes things
like HTML document traversal and manipulation, event
handling, animation, and Ajax much simpler with an easy-to-use API that
works across a multitude of browsers. With a combination of versatility
and extensibility, jQuery has changed the way that millions of people
write JavaScript.
Who's Using jQuery?
How jQuery Works
This is a basic tutorial, designed to help you get started using jQuery. If you don't have a test page setup yet, start by creating
the following HTML page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>
</head>
<body>
<a href="http://jquery.com/">jQuery</a>
<script src="jquery.js"></script>
<script>
// Your code goes here.
</script>
</body>
</html>
jQuery: The Basics
The src attribute in the <script> element must point to a copy of jQuery. Download a copy of jQuery from
the Downloading jQuery page and store t jquery.js file in the same directory as your HTML file.
Launching Code on Document Ready
To ensure that their code runs after the browser finishes loading the document, many JavaScript programmers wrap their code in an
onload function:
1
2
3
4
5
window.onload = function() {
alert( "welcome" );
}
Unfortunately, the code doesn't run until all images are finished downloading, including banner ads. To run code as soon as the
document is ready to be manipulated, jQuery has a statement known as the ready event:
1
2
3
4
5
$( document ).ready(function() {
// Your code here.
});
For example, inside the ready event, you can add a click handler to the link:
1
2
3
4
5
6
7
8
9
$( document ).ready(function() {
$( "a" ).click(function( event ) {
alert( "Thanks for visiting!" );
});
});
Save your HTML file and reload the test page in your browser. Clicking the link should now first display an alert pop-up, then
continue with the default behavior of navigating to http://jquery.com.
For click and most other events, you can prevent the default behavior by calling event.preventDefault() in the event handler:
1
2
3
4
5
6
7
8
9
1
0
1
1
$( document ).ready(function() {
$( "a" ).click(function( event ) {
alert( "As you can see, the link no longer took you to jquery.com" );
event.preventDefault();
});
});
Adding and Removing an HTML Class
Important: You must place the remaining jQuery examples inside the ready event so that your code executes when the document
is ready to be worked on.
Another common task is adding or removing a class.
First, add some style information into the <head> of the document, like this:
1
2
3
4
5
<style>
a.test {
font-weight: bold;
}
</style>
Next, add the .addClass() call to the script:
1 $( "a" ).addClass( "test" );
All <a> elements are now bold.
To remove an existing class, use .removeClass():
1 $( "a" ).removeClass( "test" );
Special Effects
jQuery also provides some handy effects to help you make your web sites
stand out. For example, if you create a click handler of:
1
2
3
4
5
6
7
$( "a" ).click(function( event ) {
event.preventDefault();
$( this ).hide( "slow" );
});
Then the link slowly disappears when clicked.
Callbacks and Functions
Unlike many other programming languages, JavaScript enables you to
freely pass functions around to be executed at a later time. A callback is a
function that is passed as an argument to another function and is executed
after its parent function has completed. Callbacks are special because they
patiently wait to execute until their parent finishes. Meanwhile, the browser
can be executing other functions or doing all sorts of other work.
To use callbacks, it is important to know how to pass them into their parent
function.
Callback without Arguments
If a callback has no arguments, you can pass it in like this:
1 $.get( "myhtmlpage.html", myCallBack );
When $.get() finishes getting the page myhtmlpage.html, it executes the myCallBack() function.
•Note: The second parameter here is simply the function name (but not as a string, and without parentheses).
Callback with Arguments
Executing callbacks with arguments can be tricky.
Wrong
This code example will not work:
1 $.get( "myhtmlpage.html", myCallBack( param1, param2 ) );
The reason this fails is that the code executes myCallBack( param1, param2 ) immediately and then passes myCallBack()'s return
value as the second parameter to $.get(). We actually want to pass the function myCallBack(), notmyCallBack( param1, param2 )'s
return value (which might or might not be a function). So, how to pass in myCallBack() andinclude its arguments?
Right
To defer executing myCallBack() with its parameters, you can use an anonymous function as a wrapper. Note the use
offunction() {. The anonymous function does exactly one thing: calls myCallBack(), with the values of param1 and param2.
1
2
3
4
5
$.get( "myhtmlpage.html", function() {
myCallBack( param1, param2 );
});
When $.get() finishes getting the page myhtmlpage.html, it executes the anonymous function, which executes
myCallBack( param1, param2 ).
Resources:
http://jquery.com/

More Related Content

What's hot (20)

PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPT
JQuery introduction
NexThoughts Technologies
 
PPT
Introduction to Javascript
Amit Tyagi
 
PDF
Php introduction
krishnapriya Tadepalli
 
PPT
jQuery
Mostafa Bayomi
 
PPTX
jQuery from the very beginning
Anis Ahmad
 
PPTX
Java script
Sadeek Mohammed
 
PDF
jQuery - Chapter 3 - Effects
WebStackAcademy
 
PPT
Document Object Model
chomas kandar
 
PPTX
JavaScript
Vidyut Singhania
 
PPT
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PDF
An introduction to React.js
Emanuele DelBono
 
PPTX
Javascript 101
Shlomi Komemi
 
PDF
ES6 presentation
ritika1
 
PPTX
Intro to React
Justin Reock
 
PPTX
Introduction to Node js
Akshay Mathur
 
jQuery for beginners
Arulmurugan Rajaraman
 
JavaScript & Dom Manipulation
Mohammed Arif
 
An Introduction to the DOM
Mindy McAdams
 
JQuery introduction
NexThoughts Technologies
 
Introduction to Javascript
Amit Tyagi
 
Php introduction
krishnapriya Tadepalli
 
jQuery from the very beginning
Anis Ahmad
 
Java script
Sadeek Mohammed
 
jQuery - Chapter 3 - Effects
WebStackAcademy
 
Document Object Model
chomas kandar
 
JavaScript
Vidyut Singhania
 
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
An introduction to React.js
Emanuele DelBono
 
Javascript 101
Shlomi Komemi
 
ES6 presentation
ritika1
 
Intro to React
Justin Reock
 
Introduction to Node js
Akshay Mathur
 

Similar to jQuery PPT (20)

PPTX
jQuery
PumoTechnovation
 
PDF
JavaScript: DOM and jQuery
維佋 唐
 
PPT
JavaScript Libraries
Daminda Herath
 
PPTX
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
PPTX
jQuery for web development
iFour Institute - Sustainable Learning
 
PPTX
Basics of Java Script (JS)
Ajay Khatri
 
PPT
jQuery and_drupal
BlackCatWeb
 
PPTX
Modern Web Technologies
Perttu Myry
 
PPT
The Theory Of The Dom
kaven yan
 
PDF
react-en.pdf
ssuser65180a
 
PDF
Jquery tutorial-beginners
Isfand yar Khan
 
PPT
eXo SEA - JavaScript Introduction Training
Hoat Le
 
PDF
Web Components v1
Mike Wilcox
 
PPT
Think jQuery
Ying Zhang
 
PPTX
Javascript first-class citizenery
toddbr
 
PPTX
Wt unit 5
team11vgnt
 
ODP
Practical catalyst
dwm042
 
PPTX
jQuery
Vishwa Mohan
 
PDF
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Nicolás Bouhid
 
PDF
Google Web Toolkit
Software Park Thailand
 
JavaScript: DOM and jQuery
維佋 唐
 
JavaScript Libraries
Daminda Herath
 
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
jQuery for web development
iFour Institute - Sustainable Learning
 
Basics of Java Script (JS)
Ajay Khatri
 
jQuery and_drupal
BlackCatWeb
 
Modern Web Technologies
Perttu Myry
 
The Theory Of The Dom
kaven yan
 
react-en.pdf
ssuser65180a
 
Jquery tutorial-beginners
Isfand yar Khan
 
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Web Components v1
Mike Wilcox
 
Think jQuery
Ying Zhang
 
Javascript first-class citizenery
toddbr
 
Wt unit 5
team11vgnt
 
Practical catalyst
dwm042
 
jQuery
Vishwa Mohan
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Nicolás Bouhid
 
Google Web Toolkit
Software Park Thailand
 
Ad

Recently uploaded (20)

PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Horarios de distribución de agua en julio
pegazohn1978
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Controller Request and Response in Odoo18
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Ad

jQuery PPT

  • 2. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
  • 4. How jQuery Works This is a basic tutorial, designed to help you get started using jQuery. If you don't have a test page setup yet, start by creating the following HTML page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <!doctype html> <html> <head> <meta charset="utf-8" /> <title>Demo</title> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src="jquery.js"></script> <script> // Your code goes here. </script> </body> </html> jQuery: The Basics The src attribute in the <script> element must point to a copy of jQuery. Download a copy of jQuery from the Downloading jQuery page and store t jquery.js file in the same directory as your HTML file.
  • 5. Launching Code on Document Ready To ensure that their code runs after the browser finishes loading the document, many JavaScript programmers wrap their code in an onload function: 1 2 3 4 5 window.onload = function() { alert( "welcome" ); } Unfortunately, the code doesn't run until all images are finished downloading, including banner ads. To run code as soon as the document is ready to be manipulated, jQuery has a statement known as the ready event: 1 2 3 4 5 $( document ).ready(function() { // Your code here. }); For example, inside the ready event, you can add a click handler to the link: 1 2 3 4 5 6 7 8 9 $( document ).ready(function() { $( "a" ).click(function( event ) { alert( "Thanks for visiting!" ); }); });
  • 6. Save your HTML file and reload the test page in your browser. Clicking the link should now first display an alert pop-up, then continue with the default behavior of navigating to http://jquery.com. For click and most other events, you can prevent the default behavior by calling event.preventDefault() in the event handler: 1 2 3 4 5 6 7 8 9 1 0 1 1 $( document ).ready(function() { $( "a" ).click(function( event ) { alert( "As you can see, the link no longer took you to jquery.com" ); event.preventDefault(); }); });
  • 7. Adding and Removing an HTML Class Important: You must place the remaining jQuery examples inside the ready event so that your code executes when the document is ready to be worked on. Another common task is adding or removing a class. First, add some style information into the <head> of the document, like this: 1 2 3 4 5 <style> a.test { font-weight: bold; } </style> Next, add the .addClass() call to the script: 1 $( "a" ).addClass( "test" ); All <a> elements are now bold. To remove an existing class, use .removeClass(): 1 $( "a" ).removeClass( "test" );
  • 8. Special Effects jQuery also provides some handy effects to help you make your web sites stand out. For example, if you create a click handler of: 1 2 3 4 5 6 7 $( "a" ).click(function( event ) { event.preventDefault(); $( this ).hide( "slow" ); }); Then the link slowly disappears when clicked.
  • 9. Callbacks and Functions Unlike many other programming languages, JavaScript enables you to freely pass functions around to be executed at a later time. A callback is a function that is passed as an argument to another function and is executed after its parent function has completed. Callbacks are special because they patiently wait to execute until their parent finishes. Meanwhile, the browser can be executing other functions or doing all sorts of other work. To use callbacks, it is important to know how to pass them into their parent function.
  • 10. Callback without Arguments If a callback has no arguments, you can pass it in like this: 1 $.get( "myhtmlpage.html", myCallBack ); When $.get() finishes getting the page myhtmlpage.html, it executes the myCallBack() function. •Note: The second parameter here is simply the function name (but not as a string, and without parentheses).
  • 11. Callback with Arguments Executing callbacks with arguments can be tricky. Wrong This code example will not work: 1 $.get( "myhtmlpage.html", myCallBack( param1, param2 ) ); The reason this fails is that the code executes myCallBack( param1, param2 ) immediately and then passes myCallBack()'s return value as the second parameter to $.get(). We actually want to pass the function myCallBack(), notmyCallBack( param1, param2 )'s return value (which might or might not be a function). So, how to pass in myCallBack() andinclude its arguments? Right To defer executing myCallBack() with its parameters, you can use an anonymous function as a wrapper. Note the use offunction() {. The anonymous function does exactly one thing: calls myCallBack(), with the values of param1 and param2. 1 2 3 4 5 $.get( "myhtmlpage.html", function() { myCallBack( param1, param2 ); }); When $.get() finishes getting the page myhtmlpage.html, it executes the anonymous function, which executes myCallBack( param1, param2 ).