SlideShare a Scribd company logo
1 of 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'});
});

More Related Content

What's hot

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) mockPranalee Rokde
 
Javascript closures
Javascript closures Javascript closures
Javascript closures VNG
 
JMockit Framework Overview
JMockit Framework OverviewJMockit Framework Overview
JMockit Framework OverviewMario Peshev
 
Junit, mockito, etc
Junit, mockito, etcJunit, mockito, etc
Junit, mockito, etcYaron Karni
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java scriptÜrgo Ringo
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About JavascriptManish Jangir
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep DiveManish Jangir
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureManish Jangir
 
Unit Testing and Mocking using MOQ
Unit Testing and Mocking using MOQUnit Testing and Mocking using MOQ
Unit Testing and Mocking using MOQBruce Johnson
 
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 TestsJohn Ferguson Smart Limited
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
J unit a starter guide
J unit a starter guideJ unit a starter guide
J unit a starter guideselfishson83
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Codeslicklash
 

What's hot (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
 

Viewers also liked (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 to Write Less, Do More with jQuery (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
 

More from Ramakrishna kapa

More from 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)
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Write Less, Do More with jQuery

  • 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'}); });