SlideShare ist ein Scribd-Unternehmen logo
1 von 23
• jQuery simplifies HTML document traversing, event handling, animating, and
Ajax interactions for rapid web development.
• jQuery is a JavaScript toolkit designed to simplify various tasks by writing
less code.
• 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
The selectors are very useful and would be required at every step while
using jQuery. They get the exact element that you want from your HTML
document.
• $('*'): This selector selects all elements in the document.
• $("#ID"): This selector function gets the element with id="ID".
• $(".Class"): This selector gets all the elements that have the class of
Class.
• $("li:not(.myclass)"): Selects all elements matched by <li> that do
not have class="myclass".
• $("a#ID.Class"): This selector matches links with an id of ID and a
class of Class.
• $("p a.Class"): This selector matches links with a class of Class
declared within <p> elements.
• $("ul li:first"): This selector gets only the first <li> element of the
<ul>.
• $("#container p"): Selects all elements matched by
<p> that are descendants of an element that has an id
of container.
• $("li > ul"): Selects all elements matched by <ul> that
are children of an element matched by <li>
• $("code, em, strong"): Selects all elements matched
by <code> or <em> or <strong>.
• $("p strong, .myclass"): Selects all elements matched
by <strong> that are descendants of an element
matched by <p> as well as all elements that have a
class of myclass.
• $(":empty"): Selects all elements that have no children.
• $("p:empty"): Selects all elements matched by <p>
that have no children.
• $("p[.myclass]"): Selects all elements matched by <p>
that contain an element with a class of myclass.
• $("a[@rel]"): Selects all elements matched by <a> that
have a rel attribute.
• $("input[@name=myname]"): Selects all elements matched by
<input> that have a name value exactly equal to myname.
• $("input[@name^=myname]"): Selects all elements matched by
<input> that have a name value beginning with myname.
• $("a[@rel$=self]"): Selects all elements matched by <p> that have a
class value ending with bar
• $("a[@href*=domain.com]"): Selects all elements matched by <a>
that have an href value containing domain.com.
• $("li:even"): Selects all elements matched by <li> that have an even
index value.
• $("tr:odd"): Selects all elements matched by <tr> that have an odd
index value.
• $("li:first"): Selects the first <li> element.
• $("li:last"): Selects the last <li> element.
• $("li:visible"): Selects all elements matched by <li> that are visible.
• $("li:hidden"): Selects all elements matched by <li> that are hidden.
• $(":radio"): Selects all radio buttons in the form.
• $(":checked"): Selects all checked boxex in the form.
• $(":input"): Selects only form elements (input, select, textarea,
button).
• $(":text"): Selects only text elements (input[type=text]).
• $("li:eq(2)"): Selects the third <li> element
• $("li:eq(4)"): Selects the fifth <li> element
• $("li:lt(2)"): Selects all elements matched by <li> element before the
third one; in other words, the first two <li> elements.
• $("p:lt(3)"): selects all elements matched by <p> elements before
the fourth one; in other words the first three <p> elements.
• $("li:gt(1)"): Selects all elements matched by <li> after the second
one.
• $("p:gt(2)"): Selects all elements matched by <p> after the third one.
• $("div/p"): Selects all elements matched by <p> that are children of
an element matched by <div>.
• $("div//code"): Selects all elements matched by <code>that are
descendants of an element matched by <div>.
• $("//p//a"): Selects all elements matched by <a> that are
descendants of an element matched by <p>
• $("li:first-child"): Selects all elements matched by <li> that are the
first child of their parent.
• $("li:last-child"): Selects all elements matched by <li> that are the
last child of their parent.
• $(":parent"): Selects all elements that are the parent of another
element, including text.
• $("li:contains(second)"): Selects all elements matched by <li> that
contain the text second.
Selector Description
eq( index ) Reduce the set of matched elements
to a single element.
$("li").eq(1)
filter( selector ) Removes all elements from the set of
matched elements that do not match
the specified selector(s).
$("li").filter(".middle").addClass("select
ed“)
Find( selector ) Searches for descendent elements
that match the specified selectors.
$("p").find("span").addClass("selected"
);
jQuery is a very powerful tool which provides a variety of DOM
traversal methods to help us select elements in a document randomly
as well as in sequential method.
We can create a event of HTML control using Jquery
mouse click, web page loading ,Taking mouse over an
element, keystroke on your keyboard.
Example-
$('div').bind('click', function( event ){
alert('Hi there!');
});
$("#driver").click(function (event) {
alert('Hi there!');
});
Event Type Description
blur Occurs when the element loses
focus
change Occurs when the element changes
click Occurs when a mouse click
error Occurs when there is an error in
loading or unloading etc.
focus Occurs when the element gets
focus
keydown Occurs when key is pressed
mousedown Occurs when mouse button is
pressed
select Occurs when a text is selected
unload Occurs when documents is
Some of the more common HTML properties, attributes.
className, tagName, id, href, title, rel, src
We can manipulate HTML attributes by using following
Jquery methods
<img id="myImage" src="image.gif" alt="An image"
class="someClass" title="This is an image"/>
Get Attribute Value
Var obj = $(“#ID").attr("title"); //Will return title of HTML control
Set Attribute Value
$("#myimg").attr("src", "/images/jquery.jpg"); // Will set src of
Image control.
Method Description
removeAttr( name ) Remove an attribute from each of the
matched elements.
$("a").removeAttr("target")
hasClass( class ) Returns true if the specified class is
present on at least one of the set of
matched elements.
attr( properties ) Set a key/value object as properties to
all matched elements.
$("#myimg").attr("src",
"/images/jquery.jpg");
removeClass( class ) Removes all or the specified class(es)
from the set of matched elements.
Method Description
toggleClass( class ) toggleClass( class )
Adds the specified class if it is not
present, removes the specified class if
it is present.
html() Get the html contents (innerHTML) of
the first matched element.
html( val ) Set the html contents of every
matched element.
text() Get the combined text contents of all
matched elements.
text (val) Set the text contents of all matched
elements.
val() Get the input value of the first matched
element.
AJAX is an acronym standing for Asynchronous JavaScript
and XML and this technology help us to load data from the
server without a browser page refresh.
$("#driver").click(function(event){
$('#stage').load('result.html');
});
• jQuery.ajax( options )
Load a remote page using an HTTP request.
• jQuery.get( url, [data], [callback], [type] )
Load a remote page using an HTTP GET request.
• jQuery.getJSON( url, [data], [callback] )
Load JSON data using an HTTP GET request.
• jQuery.post( url, [data], [callback], [type] )
Load a remote page using an HTTP POST request.
• load( url, [data], [callback] )
Load HTML from a remote file and inject it into the DOM.
$("#driver").click(function(event){
$.ajax( {
url:'/jquery/result.html',
success:function(data) {
$('#stage').html(data);
}
});
});
$("#driver").click(function(event){
$.post(
"post.aspx",
{ name: "Zara" },
function(data) {
$('#stage').html(data);
}
);
});
You can call various JQuery methods during the life cycle of AJAX call
progress. Based on different events/stages following methods are
available:
 ajaxComplete( callback )
Attach a function to be executed whenever an AJAX request
completes.
 ajaxStart( callback )
Attach a function to be executed whenever an AJAX request begins
and there is none already active.
 ajaxError( callback )
Attach a function to be executed whenever an AJAX request fails.
 ajaxSend( callback )
Attach a function to be executed before an AJAX request is sent.
 ajaxStop( callback )
Attach a function to be executed whenever all AJAX requests have
ended.
 ajaxSuccess( callback )
Attach a function to be executed whenever an AJAX request completes
successfully.
$(document).ready(function() {
$("#driver").click(function(event){
/* Assume result.text does not exist. */
$('#stage1').load('/jquery/result.text');
});
$("#stage2").ajaxError(function(event, request, settings
){
$(this).html("<h1>Error in loading page.</h1>");
});
});
jQuery provides a trivially simple interface for doing various
kind of amazing effects. jQuery methods allow us to quickly
apply commonly used effects with a minimum
configuration.
$("#show").click(function () {
$(".mydiv").show( 1000 );
});
$("#hide").click(function () {
$(".mydiv").hide( 1000 );
});
• animate( params, [duration, easing, callback] ) - A function for
making custom animations.
• fadeIn( speed, [callback] ) - Fade in all matched elements by
adjusting their opacity and firing an optional callback after
completion.
• fadeOut( speed, [callback] ) - Fade out all matched elements by
adjusting their opacity to 0, then setting display to "none" and firing
an optional callback after completion.
• fadeTo( speed, opacity, callback ) - Fade the opacity of all matched
elements to a specified opacity and firing an optional callback after
completion.
• hide( ) - Hides each of the set of matched elements if they are
shown.
• hide( speed, [callback] ) - Hide all matched elements using a graceful
animation and firing an optional callback after completion.
• show( ) - Displays each of the set of matched elements if they are
hidden.
• show( speed, [callback] ) - Show all matched elements using a
graceful animation and firing an optional callback after completion.
• slideDown( speed, [callback] ) - Reveal all matched elements by
adjusting their height and firing an optional callback after completion.
• slideToggle( speed, [callback] ) - Toggle the visibility of all matched
elements by adjusting their height and firing an optional callback
after completion.
• slideUp( speed, [callback] ) - Hide all matched elements by adjusting
their height and firing an optional callback after completion.
• stop( [clearQueue, gotoEnd ]) - Stops all the currently running
animations on all the specified elements.
Thanks

Weitere ähnliche Inhalte

Was ist angesagt?

Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Angel Ruiz
 

Was ist angesagt? (20)

J query
J queryJ query
J query
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
 
J query1
J query1J query1
J query1
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
J query training
J query trainingJ query training
J query training
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
J query introduction
J query introductionJ query introduction
J query introduction
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Learn css3
Learn css3Learn css3
Learn css3
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery Selectors
jQuery SelectorsjQuery Selectors
jQuery Selectors
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Jquery
JqueryJquery
Jquery
 
Jquery
JqueryJquery
Jquery
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 

Ähnlich wie JQuery

Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
Salvatore Fazio
 
jQuery quick tuts
jQuery quick tutsjQuery quick tuts
jQuery quick tuts
Nasa Vietnam
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
Md. Ziaul Haq
 

Ähnlich wie JQuery (20)

Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
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
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
jQuery besic
jQuery besicjQuery besic
jQuery besic
 
jQuery basics for Beginners
jQuery basics for BeginnersjQuery basics for Beginners
jQuery basics for Beginners
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptx
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery
jQueryjQuery
jQuery
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
jQuery quick tuts
jQuery quick tutsjQuery quick tuts
jQuery quick tuts
 
J query module1
J query module1J query module1
J query module1
 
Jquery for Beginners
Jquery for BeginnersJquery for Beginners
Jquery for Beginners
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQuery
 

KĂźrzlich hochgeladen

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

KĂźrzlich hochgeladen (20)

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
 
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
 
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
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
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
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

JQuery

  • 1.
  • 2. • jQuery simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. • jQuery is a JavaScript toolkit designed to simplify various tasks by writing less code. • 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
  • 3. The selectors are very useful and would be required at every step while using jQuery. They get the exact element that you want from your HTML document. • $('*'): This selector selects all elements in the document. • $("#ID"): This selector function gets the element with id="ID". • $(".Class"): This selector gets all the elements that have the class of Class. • $("li:not(.myclass)"): Selects all elements matched by <li> that do not have class="myclass". • $("a#ID.Class"): This selector matches links with an id of ID and a class of Class. • $("p a.Class"): This selector matches links with a class of Class declared within <p> elements. • $("ul li:first"): This selector gets only the first <li> element of the <ul>.
  • 4. • $("#container p"): Selects all elements matched by <p> that are descendants of an element that has an id of container. • $("li > ul"): Selects all elements matched by <ul> that are children of an element matched by <li> • $("code, em, strong"): Selects all elements matched by <code> or <em> or <strong>. • $("p strong, .myclass"): Selects all elements matched by <strong> that are descendants of an element matched by <p> as well as all elements that have a class of myclass. • $(":empty"): Selects all elements that have no children. • $("p:empty"): Selects all elements matched by <p> that have no children. • $("p[.myclass]"): Selects all elements matched by <p> that contain an element with a class of myclass. • $("a[@rel]"): Selects all elements matched by <a> that have a rel attribute.
  • 5. • $("input[@name=myname]"): Selects all elements matched by <input> that have a name value exactly equal to myname. • $("input[@name^=myname]"): Selects all elements matched by <input> that have a name value beginning with myname. • $("a[@rel$=self]"): Selects all elements matched by <p> that have a class value ending with bar • $("a[@href*=domain.com]"): Selects all elements matched by <a> that have an href value containing domain.com. • $("li:even"): Selects all elements matched by <li> that have an even index value. • $("tr:odd"): Selects all elements matched by <tr> that have an odd index value. • $("li:first"): Selects the first <li> element. • $("li:last"): Selects the last <li> element.
  • 6. • $("li:visible"): Selects all elements matched by <li> that are visible. • $("li:hidden"): Selects all elements matched by <li> that are hidden. • $(":radio"): Selects all radio buttons in the form. • $(":checked"): Selects all checked boxex in the form. • $(":input"): Selects only form elements (input, select, textarea, button). • $(":text"): Selects only text elements (input[type=text]). • $("li:eq(2)"): Selects the third <li> element • $("li:eq(4)"): Selects the fifth <li> element • $("li:lt(2)"): Selects all elements matched by <li> element before the third one; in other words, the first two <li> elements. • $("p:lt(3)"): selects all elements matched by <p> elements before the fourth one; in other words the first three <p> elements. • $("li:gt(1)"): Selects all elements matched by <li> after the second one. • $("p:gt(2)"): Selects all elements matched by <p> after the third one.
  • 7. • $("div/p"): Selects all elements matched by <p> that are children of an element matched by <div>. • $("div//code"): Selects all elements matched by <code>that are descendants of an element matched by <div>. • $("//p//a"): Selects all elements matched by <a> that are descendants of an element matched by <p> • $("li:first-child"): Selects all elements matched by <li> that are the first child of their parent. • $("li:last-child"): Selects all elements matched by <li> that are the last child of their parent. • $(":parent"): Selects all elements that are the parent of another element, including text. • $("li:contains(second)"): Selects all elements matched by <li> that contain the text second.
  • 8. Selector Description eq( index ) Reduce the set of matched elements to a single element. $("li").eq(1) filter( selector ) Removes all elements from the set of matched elements that do not match the specified selector(s). $("li").filter(".middle").addClass("select ed“) Find( selector ) Searches for descendent elements that match the specified selectors. $("p").find("span").addClass("selected" ); jQuery is a very powerful tool which provides a variety of DOM traversal methods to help us select elements in a document randomly as well as in sequential method.
  • 9. We can create a event of HTML control using Jquery mouse click, web page loading ,Taking mouse over an element, keystroke on your keyboard. Example- $('div').bind('click', function( event ){ alert('Hi there!'); }); $("#driver").click(function (event) { alert('Hi there!'); });
  • 10. Event Type Description blur Occurs when the element loses focus change Occurs when the element changes click Occurs when a mouse click error Occurs when there is an error in loading or unloading etc. focus Occurs when the element gets focus keydown Occurs when key is pressed mousedown Occurs when mouse button is pressed select Occurs when a text is selected unload Occurs when documents is
  • 11. Some of the more common HTML properties, attributes. className, tagName, id, href, title, rel, src We can manipulate HTML attributes by using following Jquery methods <img id="myImage" src="image.gif" alt="An image" class="someClass" title="This is an image"/> Get Attribute Value Var obj = $(“#ID").attr("title"); //Will return title of HTML control Set Attribute Value $("#myimg").attr("src", "/images/jquery.jpg"); // Will set src of Image control.
  • 12. Method Description removeAttr( name ) Remove an attribute from each of the matched elements. $("a").removeAttr("target") hasClass( class ) Returns true if the specified class is present on at least one of the set of matched elements. attr( properties ) Set a key/value object as properties to all matched elements. $("#myimg").attr("src", "/images/jquery.jpg"); removeClass( class ) Removes all or the specified class(es) from the set of matched elements.
  • 13. Method Description toggleClass( class ) toggleClass( class ) Adds the specified class if it is not present, removes the specified class if it is present. html() Get the html contents (innerHTML) of the first matched element. html( val ) Set the html contents of every matched element. text() Get the combined text contents of all matched elements. text (val) Set the text contents of all matched elements. val() Get the input value of the first matched element.
  • 14. AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology help us to load data from the server without a browser page refresh. $("#driver").click(function(event){ $('#stage').load('result.html'); });
  • 15. • jQuery.ajax( options ) Load a remote page using an HTTP request. • jQuery.get( url, [data], [callback], [type] ) Load a remote page using an HTTP GET request. • jQuery.getJSON( url, [data], [callback] ) Load JSON data using an HTTP GET request. • jQuery.post( url, [data], [callback], [type] ) Load a remote page using an HTTP POST request. • load( url, [data], [callback] ) Load HTML from a remote file and inject it into the DOM.
  • 17. $("#driver").click(function(event){ $.post( "post.aspx", { name: "Zara" }, function(data) { $('#stage').html(data); } ); });
  • 18. You can call various JQuery methods during the life cycle of AJAX call progress. Based on different events/stages following methods are available:  ajaxComplete( callback ) Attach a function to be executed whenever an AJAX request completes.  ajaxStart( callback ) Attach a function to be executed whenever an AJAX request begins and there is none already active.  ajaxError( callback ) Attach a function to be executed whenever an AJAX request fails.  ajaxSend( callback ) Attach a function to be executed before an AJAX request is sent.  ajaxStop( callback ) Attach a function to be executed whenever all AJAX requests have ended.  ajaxSuccess( callback ) Attach a function to be executed whenever an AJAX request completes successfully.
  • 19. $(document).ready(function() { $("#driver").click(function(event){ /* Assume result.text does not exist. */ $('#stage1').load('/jquery/result.text'); }); $("#stage2").ajaxError(function(event, request, settings ){ $(this).html("<h1>Error in loading page.</h1>"); }); });
  • 20. jQuery provides a trivially simple interface for doing various kind of amazing effects. jQuery methods allow us to quickly apply commonly used effects with a minimum configuration. $("#show").click(function () { $(".mydiv").show( 1000 ); }); $("#hide").click(function () { $(".mydiv").hide( 1000 ); });
  • 21. • animate( params, [duration, easing, callback] ) - A function for making custom animations. • fadeIn( speed, [callback] ) - Fade in all matched elements by adjusting their opacity and firing an optional callback after completion. • fadeOut( speed, [callback] ) - Fade out all matched elements by adjusting their opacity to 0, then setting display to "none" and firing an optional callback after completion. • fadeTo( speed, opacity, callback ) - Fade the opacity of all matched elements to a specified opacity and firing an optional callback after completion. • hide( ) - Hides each of the set of matched elements if they are shown. • hide( speed, [callback] ) - Hide all matched elements using a graceful animation and firing an optional callback after completion.
  • 22. • show( ) - Displays each of the set of matched elements if they are hidden. • show( speed, [callback] ) - Show all matched elements using a graceful animation and firing an optional callback after completion. • slideDown( speed, [callback] ) - Reveal all matched elements by adjusting their height and firing an optional callback after completion. • slideToggle( speed, [callback] ) - Toggle the visibility of all matched elements by adjusting their height and firing an optional callback after completion. • slideUp( speed, [callback] ) - Hide all matched elements by adjusting their height and firing an optional callback after completion. • stop( [clearQueue, gotoEnd ]) - Stops all the currently running animations on all the specified elements.