SlideShare una empresa de Scribd logo
1 de 12
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/

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Javascript
JavascriptJavascript
Javascript
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
JavaScript
JavaScriptJavaScript
JavaScript
 
jQuery
jQueryjQuery
jQuery
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Dom
DomDom
Dom
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 

Similar a jQuery PPT

Similar a jQuery PPT (20)

jQuery
jQueryjQuery
jQuery
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
JavaScript Libraries
JavaScript LibrariesJavaScript Libraries
JavaScript Libraries
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
react-en.pdf
react-en.pdfreact-en.pdf
react-en.pdf
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Think jQuery
Think jQueryThink jQuery
Think jQuery
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
jQuery
jQueryjQuery
jQuery
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQuery
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

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 ).