SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
jQueryWRITE LESS, DO MORE
1
INTRODUCTION
2
jQuery
 Open source Javascript framework
 Crossbrowser client side scripting
 Uses CSS syntax for selection
 Most used Javascript library
 $ - synonymous with the jQuery function
3
Loading jQuery
Locally : <script src="/js/jquery.js">
CDN :
 ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
 ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js
BEST PRACTICE :
When scripts are downloading they block everything else in almost
all browsers. Load scripts at the bottom of the page so they don't
interrupt page content downloads.
4
Ready state
 The DOM is "ready" when everything on the page has loaded.
 Stylesheets
 JavaScripts
 Images
 In order to make sure that jQuery can find all the elements, wrap the
jQuery code within in the document ready function.
$(document).ready(function(){ … });
$(function() { … });
5
Selecting elements
Selector Reference :
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
 Pseudo selectors (:) - :first, :button, :input, :checked
 Filtering selectors – has, not, filter, eq
Testing Selectors :
http://www.w3schools.com/jquery/trysel.asp
CONVENTION :
When storing selections in a variable prefix ‘$’ to indicate that the variable
contains a jQuery object.
6
Getters and setters
 GET :
var htmlContent = $(“selector”).html()
var textContent = $(“selector”).text()
 SET :
$(“selector”).html(‘content’)
$(“selector”).text(‘content’)
 Example :
https://jsfiddle.net/NivedhithaV/aw9q87b5/2/
For form elements val() is used
7
Iteration
$( 'li' ).each(function( index, elem ) {
// this: the current DOM element
// index: the current element's index in the selection
// elem: the current DOM element (same as this)
$( elem ).prepend( '<b>' + index + ': </b>' );
});
Example :
https://jsfiddle.net/NivedhithaV/2shq5x69/1/
8
Chaining
CALLING A SERIES OF METHODS ON A SELECTION WITHOUT REPEATING
THE SELECTOR
9
TRAVERSING &
MANIPULATING THE
DOM
10
Selecting elements relative to
another element
 First
 Siblings
 Prev / next
 Parent
 Parents
 Children
 Find
 closest
11
Manipulating Style
 Indrirectly using classes
 addClass
 removeClass
 toggleClass
 Directly styling elements
 $(“selector”).css(“property”, “value”)
 $(“selector”).css({
“property”, “value”,
“property”, “value”…
})
12
EVENTS
13
Binding events
 Events –
 Click, dblclick, change, blur, focus
 Mouse events
 Keyboard events
 Bind/unbind – connecting/disconnecting event handler
 One – connecting events to run only once
 On – attaching one or more events, will work for current and future
elements
 Trigger – triggering an event after binding
14
Other functions
 preventDefault – prevents the default action of the event
$( "a" ).click(function( event ) {
event.preventDefault();
...
});
 stopPropogation – prevents event from bubbling up to parent
 Example : https://jsfiddle.net/NivedhithaV/32rvk8zk/1/
15
EFFECTS
16
Built-in effects
 Effects
 Show/hide
 fadeIn/fadeOut
 SlideUp/slideDown/slideToggle
 Duration
 Effect(duration in ms)
 Slow/fast
 Custom effects – animate()
17
AJAX
18
Asynchronous javascript and XML
 Loading data from server without page reload
 Uses Xmlhttprequest - XHR
 Returns jqXHR object — a jQuery XML HTTP Request
 Form serialize
 Example - https://jsfiddle.net/NivedhithaV/mhJRQ/9/
19
 $.ajax
$.ajax({
url: ‘/sample-url',
dataType: 'json',
success: function( data) {
//callback
},
error: function( req, status, err ) {
//error
}
});
20
 $.get – non destructive operations
$.get( ‘/sample-url', function( html ){
$( '#target' ).html( html );
});
 $.post – destructive operations
$.post( '/sample-url', { key: ‘value' },
function( data) {
console.log( data);
});
21
jqXHR
var data = $.ajax({
url: '/sample-url',
dataType: 'json'
});
 Then
 Done
 Fail
 Always
22
Questions?
23

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery presentation
jQuery presentationjQuery presentation
jQuery presentationMahesh Reddy
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryDon't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryshabab shihan
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party AuthenticationAaron Brazell
 
jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');mikehostetler
 
Jquery for post a form
Jquery for post a formJquery for post a form
Jquery for post a formRakesh Kumar
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebRobert Nyman
 
Casl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptxCasl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptxSergiy Stotskiy
 
Java script browser objects 2
Java script browser objects 2Java script browser objects 2
Java script browser objects 2H K
 
JQuery Comprehensive Overview
JQuery Comprehensive OverviewJQuery Comprehensive Overview
JQuery Comprehensive OverviewMohamed Loey
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to JqueryAmzad Hossain
 

Was ist angesagt? (20)

jQuery presentation
jQuery presentationjQuery presentation
jQuery presentation
 
Owasp & php
Owasp & phpOwasp & php
Owasp & php
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryDon't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQuery
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');
 
Jquery for post a form
Jquery for post a formJquery for post a form
Jquery for post a form
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
NodeJS in Windows Azure
NodeJS in Windows AzureNodeJS in Windows Azure
NodeJS in Windows Azure
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
 
YUI3 - IIT Madras HackU
YUI3 - IIT Madras HackU YUI3 - IIT Madras HackU
YUI3 - IIT Madras HackU
 
OUTDATED (Encore)
OUTDATED (Encore)OUTDATED (Encore)
OUTDATED (Encore)
 
Canjs
CanjsCanjs
Canjs
 
Jquery Cheatsheet
Jquery CheatsheetJquery Cheatsheet
Jquery Cheatsheet
 
Casl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptxCasl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptx
 
Java script browser objects 2
Java script browser objects 2Java script browser objects 2
Java script browser objects 2
 
JQuery Comprehensive Overview
JQuery Comprehensive OverviewJQuery Comprehensive Overview
JQuery Comprehensive Overview
 
Jquery image slider
Jquery image slider Jquery image slider
Jquery image slider
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 

Andere mochten auch

Assurance and Performance Framework presentation
Assurance and Performance Framework presentationAssurance and Performance Framework presentation
Assurance and Performance Framework presentationMartin Gavet
 
Você se considera um profissional de alta produtividade?
Você se considera um profissional de alta produtividade?Você se considera um profissional de alta produtividade?
Você se considera um profissional de alta produtividade?Mariana de Góes Borges
 
Liberate-Strategy-2014-18-v.1
Liberate-Strategy-2014-18-v.1Liberate-Strategy-2014-18-v.1
Liberate-Strategy-2014-18-v.1Martin Gavet
 
Whyalla News -Experiencing the workforce
Whyalla News -Experiencing the workforceWhyalla News -Experiencing the workforce
Whyalla News -Experiencing the workforceBaerbel McDougall
 
Il come e il perchè
Il come e il perchèIl come e il perchè
Il come e il perchèBernardo1969
 
Wales German Network reference
Wales German Network referenceWales German Network reference
Wales German Network referenceStephen Parkinson
 
Prontos para mais uma transformação? Bem vindo ao mundo digital!
Prontos para mais uma transformação? Bem vindo ao mundo digital!Prontos para mais uma transformação? Bem vindo ao mundo digital!
Prontos para mais uma transformação? Bem vindo ao mundo digital!Mariana de Góes Borges
 
Brochure: Aurora Mobile
Brochure: Aurora MobileBrochure: Aurora Mobile
Brochure: Aurora MobileSue Niemiec
 
2 safety precautions
2 safety precautions2 safety precautions
2 safety precautionsmiamore07
 

Andere mochten auch (12)

Snm 9872346154
Snm 9872346154Snm 9872346154
Snm 9872346154
 
Assurance and Performance Framework presentation
Assurance and Performance Framework presentationAssurance and Performance Framework presentation
Assurance and Performance Framework presentation
 
Você se considera um profissional de alta produtividade?
Você se considera um profissional de alta produtividade?Você se considera um profissional de alta produtividade?
Você se considera um profissional de alta produtividade?
 
Liberate-Strategy-2014-18-v.1
Liberate-Strategy-2014-18-v.1Liberate-Strategy-2014-18-v.1
Liberate-Strategy-2014-18-v.1
 
Whyalla News -Experiencing the workforce
Whyalla News -Experiencing the workforceWhyalla News -Experiencing the workforce
Whyalla News -Experiencing the workforce
 
Il come e il perchè
Il come e il perchèIl come e il perchè
Il come e il perchè
 
Wales German Network reference
Wales German Network referenceWales German Network reference
Wales German Network reference
 
Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3
 
Prontos para mais uma transformação? Bem vindo ao mundo digital!
Prontos para mais uma transformação? Bem vindo ao mundo digital!Prontos para mais uma transformação? Bem vindo ao mundo digital!
Prontos para mais uma transformação? Bem vindo ao mundo digital!
 
Brochure: Aurora Mobile
Brochure: Aurora MobileBrochure: Aurora Mobile
Brochure: Aurora Mobile
 
ccv
ccvccv
ccv
 
2 safety precautions
2 safety precautions2 safety precautions
2 safety precautions
 

Ähnlich wie Introduction to jQuery

Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterIvo Andreev
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012ghnash
 
JavaScript patterns chapter 8 of mine
JavaScript patterns chapter 8 of mineJavaScript patterns chapter 8 of mine
JavaScript patterns chapter 8 of mineChien-Wei Huang
 
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...Thinqloud
 
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 JQuerykolkatageeks
 
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 .NETJames Johnson
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
 
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 .NETJames Johnson
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQueryLaurence Svekis ✔
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 

Ähnlich wie Introduction to jQuery (20)

Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform better
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Web2 - jQuery
Web2 - jQueryWeb2 - jQuery
Web2 - jQuery
 
JavaScript patterns chapter 8 of mine
JavaScript patterns chapter 8 of mineJavaScript patterns chapter 8 of mine
JavaScript patterns chapter 8 of mine
 
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...
 
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
 
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 training
J query trainingJ query training
J query training
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
Lec 5
Lec 5Lec 5
Lec 5
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
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
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
DrupalCon jQuery
DrupalCon jQueryDrupalCon jQuery
DrupalCon jQuery
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQueryUI
 jQueryUI jQueryUI
jQueryUI
 

Kürzlich hochgeladen

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Introduction to jQuery

  • 3. jQuery  Open source Javascript framework  Crossbrowser client side scripting  Uses CSS syntax for selection  Most used Javascript library  $ - synonymous with the jQuery function 3
  • 4. Loading jQuery Locally : <script src="/js/jquery.js"> CDN :  ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js  ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js BEST PRACTICE : When scripts are downloading they block everything else in almost all browsers. Load scripts at the bottom of the page so they don't interrupt page content downloads. 4
  • 5. Ready state  The DOM is "ready" when everything on the page has loaded.  Stylesheets  JavaScripts  Images  In order to make sure that jQuery can find all the elements, wrap the jQuery code within in the document ready function. $(document).ready(function(){ … }); $(function() { … }); 5
  • 6. Selecting elements Selector Reference : http://www.w3schools.com/jquery/jquery_ref_selectors.asp  Pseudo selectors (:) - :first, :button, :input, :checked  Filtering selectors – has, not, filter, eq Testing Selectors : http://www.w3schools.com/jquery/trysel.asp CONVENTION : When storing selections in a variable prefix ‘$’ to indicate that the variable contains a jQuery object. 6
  • 7. Getters and setters  GET : var htmlContent = $(“selector”).html() var textContent = $(“selector”).text()  SET : $(“selector”).html(‘content’) $(“selector”).text(‘content’)  Example : https://jsfiddle.net/NivedhithaV/aw9q87b5/2/ For form elements val() is used 7
  • 8. Iteration $( 'li' ).each(function( index, elem ) { // this: the current DOM element // index: the current element's index in the selection // elem: the current DOM element (same as this) $( elem ).prepend( '<b>' + index + ': </b>' ); }); Example : https://jsfiddle.net/NivedhithaV/2shq5x69/1/ 8
  • 9. Chaining CALLING A SERIES OF METHODS ON A SELECTION WITHOUT REPEATING THE SELECTOR 9
  • 11. Selecting elements relative to another element  First  Siblings  Prev / next  Parent  Parents  Children  Find  closest 11
  • 12. Manipulating Style  Indrirectly using classes  addClass  removeClass  toggleClass  Directly styling elements  $(“selector”).css(“property”, “value”)  $(“selector”).css({ “property”, “value”, “property”, “value”… }) 12
  • 14. Binding events  Events –  Click, dblclick, change, blur, focus  Mouse events  Keyboard events  Bind/unbind – connecting/disconnecting event handler  One – connecting events to run only once  On – attaching one or more events, will work for current and future elements  Trigger – triggering an event after binding 14
  • 15. Other functions  preventDefault – prevents the default action of the event $( "a" ).click(function( event ) { event.preventDefault(); ... });  stopPropogation – prevents event from bubbling up to parent  Example : https://jsfiddle.net/NivedhithaV/32rvk8zk/1/ 15
  • 17. Built-in effects  Effects  Show/hide  fadeIn/fadeOut  SlideUp/slideDown/slideToggle  Duration  Effect(duration in ms)  Slow/fast  Custom effects – animate() 17
  • 19. Asynchronous javascript and XML  Loading data from server without page reload  Uses Xmlhttprequest - XHR  Returns jqXHR object — a jQuery XML HTTP Request  Form serialize  Example - https://jsfiddle.net/NivedhithaV/mhJRQ/9/ 19
  • 20.  $.ajax $.ajax({ url: ‘/sample-url', dataType: 'json', success: function( data) { //callback }, error: function( req, status, err ) { //error } }); 20
  • 21.  $.get – non destructive operations $.get( ‘/sample-url', function( html ){ $( '#target' ).html( html ); });  $.post – destructive operations $.post( '/sample-url', { key: ‘value' }, function( data) { console.log( data); }); 21
  • 22. jqXHR var data = $.ajax({ url: '/sample-url', dataType: 'json' });  Then  Done  Fail  Always 22