SlideShare una empresa de Scribd logo
1 de 15
jQuery is a fast and concise JavaScript Library created by John
Resig in 2006 with a nice motto − Write less, do more.
jQuery simplifies HTML document traversing, event handling,
animating, and Ajax interactions for rapid web development.
JQuery features
 DOM manipulation − The jQuery made it easy to select DOM
elements, traverse them and modifying their content by using cross-
browser open source selector engine called Sizzle.
 Event handling − The jQuery offers an elegant way to capture a wide
variety of events, such as a user clicking on a link, without the need to
clutter the HTML code itself with event handlers.
 AJAX Support − The jQuery helps you a lot to develop a responsive
and feature-rich site using AJAX technology.
 Animations − The jQuery comes with plenty of built-in animation
effects which you can use in your websites.
 Lightweight − The jQuery is very lightweight library - about 19KB in
size ( Minified and gzipped ).
 Cross Browser Support − The jQuery has cross-browser support, and
works well in IE 6.0+, FF 2.0+, Safari 3.0+, Chrome and Opera 9.0+
 Latest Technology − The jQuery supports CSS3 selectors and basic
XPath syntax.
How to use jQuery?
 There are two ways to use jQuery.
 Local Installation − You can download jQuery library on your local
machine and include it in your HTML code.
 CDN Based Version − You can include jQuery library into your HTML
code directly from Content Delivery Network (CDN).
 Local Installation
 Go to the https://jquery.com/download/ to download the latest version
available.
 Now put downloaded jquery-2.1.3.min.js file in a directory of your
website, e.g. /jquery
 The jQuery library is a single JavaScript file, and you reference it with the
HTML <script> tag (notice that the <script> tag should be inside the
<head> section):
 <head>
<script src="jquery-1.12.2.min.js"></script>
</head>
 jQuery CDN
 If you don't want to download and host jQuery yourself, you can include it
from a CDN (Content Delivery Network).
 Both Google and Microsoft host jQuery.
 To use jQuery from Google or Microsoft, use one of the following:
 <head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min
.js"></script>
</head>
jQuery Syntax
 The jQuery syntax is tailor-made for selecting HTML elements and
performing some action on the element(s).
 Basic syntax is: $(selector).action()
 A $ sign to define/access jQuery
 A (selector) to "query (or find)" HTML elements
 A jQuery action() to be performed on the element(s)
 Examples:
 $(this).hide() - hides the current element.
 $("p").hide() - hides all <p> elements.
 $(".test").hide() - hides all elements with class="test".
 $("#test").hide() - hides the element with id="test".

The Document Ready Event
 $(document).ready(function(){
// jQuery methods go here...
});
 This is to prevent any jQuery code from running before the document is finished
loading (is ready).
 It is good practice to wait for the document to be fully loaded and ready before
working with it. This also allows you to have your JavaScript code before the body of
your document, in the head section.
 Here are some examples of actions that can fail if methods are run before the
document is fully loaded:
 Trying to hide an element that is not created yet
 Trying to get the size of an image that is not loaded yet
 Tip: The jQuery team has also created an even shorter method for the document
ready event:
jQuery Selectors
 jQuery Selectors
 jQuery selectors allow you to select and manipulate HTML element(s).
 jQuery selectors are used to "find" (or select) HTML elements based on their name,
id, classes, types, attributes, values of attributes and much more. It's based on the
existing CSS Selectors, and in addition, it has some own custom selectors.
 All selectors in jQuery start with the dollar sign and parentheses: $().
 The jQuery element selector selects elements based on the element name.
 You can select all <p> elements on a page like this: $("p").
 Example
 $(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
The #id Selector
 The jQuery #id selector uses the id attribute of an HTML tag to find
the specific element.
 An id should be unique within a page, so you should use the #id
selector when you want to find a single, unique element.
 To find an element with a specific id, write a hash character, followed
by the id of the HTML element: $("#test")
 $(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
The .class Selector
 The jQuery class selector finds elements with a specific class.
 To find elements with a specific class, write a period character, followed by
the name of the class:
 $(".test")
 Example
 When a user clicks on a button, the elements with class="test" will be
hidden:
 Example
 $(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
jQuery Event Methods
 What are Events?
 All the different visitor's actions that a web page can respond to are
called events.
 An event represents the precise moment when something happens.
 Examples:
 moving a mouse over an element
 selecting a radio button
 clicking on an element
 The term "fires/fired" is often used with events. Example: "The
keypress event is fired, the moment you press a key".
 Here are some common DOM events:
DOM events
Mouse Events Keyboard Events Form Events Document/Window
Events
click keypress submit load
dblclick keydown change resize
mouseenter keyup focus scroll
mouseleave blur unload
jQuery Syntax For Event Methods
 In jQuery, most DOM events have an equivalent jQuery method.
 To assign a click event to all paragraphs on a page, you can do this:
 $("p").click();
 The next step is to define what should happen when the event fires.
You must pass a function to the event:
 $("p").click(function(){
// action goes here!!
});
Commonly Used jQuery Event Methods
 $(document).ready()
 The $(document).ready() method allows us to execute a function
when the document is fully loaded.
 click()
 The click() method attaches an event handler function to an
HTML element.
 The function is executed when the user clicks on the HTML
element.
 The following example says: When a click event fires on a <p>
element; hide the current <p> element:
 Example
 $("p").click(function(){
$(this).hide();
});
jQuery Effects - Hide and Show
 Examples
 jQuery hide()
Demonstrates a simple jQuery hide() method.
 jQuery hide()
Another hide() demonstration. How to hide parts of text.
 jQuery hide() and show()
 With jQuery, you can hide and show HTML elements with the hide() and show()
methods:
 Example
 $("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
jQuery Animations - The animate() Method
 The jQuery animate() method is used to create custom animations.
 Syntax:
 $(selector).animate({params},speed,callback);
 The required params parameter defines the CSS properties to be animated.
 The optional speed parameter specifies the duration of the effect. It can take
the following values: "slow", "fast", or milliseconds.
 The optional callback parameter is a function to be executed after the
animation completes.
 The following example demonstrates a simple use of the animate() method; it
moves a <div> element to the right, until it has reached a left property of 250px:
 Example
 $("button").click(function(){
$("div").animate({left: '250px'});
});

Más contenido relacionado

La actualidad más candente

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 

La actualidad más candente (20)

All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
 
Power mock
Power mockPower mock
Power mock
 
Javascript closures
Javascript closures Javascript closures
Javascript closures
 
JMockit Framework Overview
JMockit Framework OverviewJMockit Framework Overview
JMockit Framework Overview
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etc
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Java script basic
Java script basicJava script basic
Java script basic
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About Javascript
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Unit Testing and Mocking using MOQ
Unit Testing and Mocking using MOQUnit Testing and Mocking using MOQ
Unit Testing and Mocking using MOQ
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit Tests
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Test doubles
Test doublesTest doubles
Test doubles
 
J unit a starter guide
J unit a starter guideJ unit a starter guide
J unit a starter guide
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Code
 

Destacado (20)

Amazon web services aws
Amazon web services awsAmazon web services aws
Amazon web services aws
 
Go programing language
Go programing languageGo programing language
Go programing language
 
Apache poi tutorial
Apache poi tutorialApache poi tutorial
Apache poi tutorial
 
Mule exception strategies
Mule exception strategiesMule exception strategies
Mule exception strategies
 
Design pattern
Design patternDesign pattern
Design pattern
 
Java.util
Java.utilJava.util
Java.util
 
Cassandra tutorial
Cassandra tutorialCassandra tutorial
Cassandra tutorial
 
Test ng
Test ngTest ng
Test ng
 
Jsf 2
Jsf 2Jsf 2
Jsf 2
 
Mule raml
Mule ramlMule raml
Mule raml
 
Rest component demo
Rest component demoRest component demo
Rest component demo
 
Anypoint connectors
Anypoint connectorsAnypoint connectors
Anypoint connectors
 
Groovy demo
Groovy demoGroovy demo
Groovy demo
 
Scopes in mule
Scopes in muleScopes in mule
Scopes in mule
 
Angular js
Angular jsAngular js
Angular js
 
Jsoup tutorial
Jsoup tutorialJsoup tutorial
Jsoup tutorial
 
Mule global elements
Mule global elementsMule global elements
Mule global elements
 
Hsqldb tutorial
Hsqldb tutorialHsqldb tutorial
Hsqldb tutorial
 
How to create an api in mule
How to create an api in muleHow to create an api in mule
How to create an api in mule
 
Vm transport
Vm transportVm transport
Vm transport
 

Similar a J query

Similar a J query (20)

Jquery
JqueryJquery
Jquery
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
jQuery
jQueryjQuery
jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
jQuery
jQueryjQuery
jQuery
 
Jquery library
Jquery libraryJquery library
Jquery library
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introduction to jquery mobile with Phonegap
Introduction to jquery mobile with PhonegapIntroduction to jquery mobile with Phonegap
Introduction to jquery mobile with Phonegap
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
J query training
J query trainingJ query training
J query training
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
JavaScript Libraries
JavaScript LibrariesJavaScript Libraries
JavaScript Libraries
 
JQuery
JQueryJQuery
JQuery
 
jQuery
jQueryjQuery
jQuery
 

Más de Ramakrishna kapa

Más de Ramakrishna kapa (20)

Load balancer in mule
Load balancer in muleLoad balancer in mule
Load balancer in mule
 
Batch processing
Batch processingBatch processing
Batch processing
 
Msmq connectivity
Msmq connectivityMsmq connectivity
Msmq connectivity
 
Data weave more operations
Data weave more operationsData weave more operations
Data weave more operations
 
Basic math operations using dataweave
Basic math operations using dataweaveBasic math operations using dataweave
Basic math operations using dataweave
 
Dataweave types operators
Dataweave types operatorsDataweave types operators
Dataweave types operators
 
Operators in mule dataweave
Operators in mule dataweaveOperators in mule dataweave
Operators in mule dataweave
 
Data weave in mule
Data weave in muleData weave in mule
Data weave in mule
 
Servicenow connector
Servicenow connectorServicenow connector
Servicenow connector
 
Introduction to testing mule
Introduction to testing muleIntroduction to testing mule
Introduction to testing mule
 
Choice flow control
Choice flow controlChoice flow control
Choice flow control
 
Message enricher example
Message enricher exampleMessage enricher example
Message enricher example
 
Anypoint connector basics
Anypoint connector basicsAnypoint connector basics
Anypoint connector basics
 
Mule message structure and varibles scopes
Mule message structure and varibles scopesMule message structure and varibles scopes
Mule message structure and varibles scopes
 
Log4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexibleLog4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexible
 
Vi editor
Vi editorVi editor
Vi editor
 
Mongo db
Mongo dbMongo db
Mongo db
 
Apache h base
Apache h baseApache h base
Apache h base
 
Ruby in mule
Ruby in muleRuby in mule
Ruby in mule
 
Dcn(data communication and computer network)
Dcn(data communication and computer network)Dcn(data communication and computer network)
Dcn(data communication and computer network)
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

J query

  • 1. jQuery is a fast and concise JavaScript Library created by John Resig in 2006 with a nice motto − Write less, do more. jQuery simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
  • 2. JQuery features  DOM manipulation − The jQuery made it easy to select DOM elements, traverse them and modifying their content by using cross- browser open source selector engine called Sizzle.  Event handling − The jQuery offers an elegant way to capture a wide variety of events, such as a user clicking on a link, without the need to clutter the HTML code itself with event handlers.  AJAX Support − The jQuery helps you a lot to develop a responsive and feature-rich site using AJAX technology.  Animations − The jQuery comes with plenty of built-in animation effects which you can use in your websites.  Lightweight − The jQuery is very lightweight library - about 19KB in size ( Minified and gzipped ).  Cross Browser Support − The jQuery has cross-browser support, and works well in IE 6.0+, FF 2.0+, Safari 3.0+, Chrome and Opera 9.0+  Latest Technology − The jQuery supports CSS3 selectors and basic XPath syntax.
  • 3. How to use jQuery?  There are two ways to use jQuery.  Local Installation − You can download jQuery library on your local machine and include it in your HTML code.  CDN Based Version − You can include jQuery library into your HTML code directly from Content Delivery Network (CDN).  Local Installation  Go to the https://jquery.com/download/ to download the latest version available.  Now put downloaded jquery-2.1.3.min.js file in a directory of your website, e.g. /jquery
  • 4.  The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag (notice that the <script> tag should be inside the <head> section):  <head> <script src="jquery-1.12.2.min.js"></script> </head>  jQuery CDN  If you don't want to download and host jQuery yourself, you can include it from a CDN (Content Delivery Network).  Both Google and Microsoft host jQuery.  To use jQuery from Google or Microsoft, use one of the following:  <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min .js"></script> </head>
  • 5. jQuery Syntax  The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).  Basic syntax is: $(selector).action()  A $ sign to define/access jQuery  A (selector) to "query (or find)" HTML elements  A jQuery action() to be performed on the element(s)  Examples:  $(this).hide() - hides the current element.  $("p").hide() - hides all <p> elements.  $(".test").hide() - hides all elements with class="test".  $("#test").hide() - hides the element with id="test". 
  • 6. The Document Ready Event  $(document).ready(function(){ // jQuery methods go here... });  This is to prevent any jQuery code from running before the document is finished loading (is ready).  It is good practice to wait for the document to be fully loaded and ready before working with it. This also allows you to have your JavaScript code before the body of your document, in the head section.  Here are some examples of actions that can fail if methods are run before the document is fully loaded:  Trying to hide an element that is not created yet  Trying to get the size of an image that is not loaded yet  Tip: The jQuery team has also created an even shorter method for the document ready event:
  • 7. jQuery Selectors  jQuery Selectors  jQuery selectors allow you to select and manipulate HTML element(s).  jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.  All selectors in jQuery start with the dollar sign and parentheses: $().  The jQuery element selector selects elements based on the element name.  You can select all <p> elements on a page like this: $("p").  Example  $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); });
  • 8. The #id Selector  The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.  An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.  To find an element with a specific id, write a hash character, followed by the id of the HTML element: $("#test")  $(document).ready(function(){ $("button").click(function(){ $("#test").hide(); }); });
  • 9. The .class Selector  The jQuery class selector finds elements with a specific class.  To find elements with a specific class, write a period character, followed by the name of the class:  $(".test")  Example  When a user clicks on a button, the elements with class="test" will be hidden:  Example  $(document).ready(function(){ $("button").click(function(){ $(".test").hide(); }); });
  • 10. jQuery Event Methods  What are Events?  All the different visitor's actions that a web page can respond to are called events.  An event represents the precise moment when something happens.  Examples:  moving a mouse over an element  selecting a radio button  clicking on an element  The term "fires/fired" is often used with events. Example: "The keypress event is fired, the moment you press a key".  Here are some common DOM events:
  • 11. DOM events Mouse Events Keyboard Events Form Events Document/Window Events click keypress submit load dblclick keydown change resize mouseenter keyup focus scroll mouseleave blur unload
  • 12. jQuery Syntax For Event Methods  In jQuery, most DOM events have an equivalent jQuery method.  To assign a click event to all paragraphs on a page, you can do this:  $("p").click();  The next step is to define what should happen when the event fires. You must pass a function to the event:  $("p").click(function(){ // action goes here!! });
  • 13. Commonly Used jQuery Event Methods  $(document).ready()  The $(document).ready() method allows us to execute a function when the document is fully loaded.  click()  The click() method attaches an event handler function to an HTML element.  The function is executed when the user clicks on the HTML element.  The following example says: When a click event fires on a <p> element; hide the current <p> element:  Example  $("p").click(function(){ $(this).hide(); });
  • 14. jQuery Effects - Hide and Show  Examples  jQuery hide() Demonstrates a simple jQuery hide() method.  jQuery hide() Another hide() demonstration. How to hide parts of text.  jQuery hide() and show()  With jQuery, you can hide and show HTML elements with the hide() and show() methods:  Example  $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); });
  • 15. jQuery Animations - The animate() Method  The jQuery animate() method is used to create custom animations.  Syntax:  $(selector).animate({params},speed,callback);  The required params parameter defines the CSS properties to be animated.  The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.  The optional callback parameter is a function to be executed after the animation completes.  The following example demonstrates a simple use of the animate() method; it moves a <div> element to the right, until it has reached a left property of 250px:  Example  $("button").click(function(){ $("div").animate({left: '250px'}); });