SlideShare una empresa de Scribd logo
1 de 38
jQuery
A Javascript Library
Hard things made eas(ier)
jQuery
• Javascript Library to do many, many things
that would normally require intricate
knowledge of javascript, different browsers,
and different devices.
• (Fairly) easy to learn
• You should try all the examples on
http://www.w3schools.com/jquery
Or take the code Academy JQuery course.
http://www.codeacademy.com
Simple example
Function which hides a <p> element when clicked
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("p").click(function() {
$(this).hide();
}
);
}
);
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
</body>
</html>
jQuery Overview
• What is jQuery?
• jQuery is a library of JavaScript Functions.
• jQuery is a lightweight "write less, do more" JavaScript library.
• The jQuery library contains the following features:
– HTML element selections
– HTML element manipulation
– CSS manipulation
– HTML event functions
– JavaScript Effects and animations
– HTML DOM traversal and modification
– AJAX
– Utilities
Using jQuery
Just include the library
<head>
<script type="text/javascript"
src="jquery.js"></script>
</head>
Simple jQuery
Click button to hide all paragraphs
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me and things will be hidden</button>
</body>
</html>
jQuery Syntax Examples
$ indicates a jQuery statement
(Note CSS Style References)
• $(this).hide()
Demonstrates the jQuery hide() method, hiding the current
HTML element.
• $("#test").hide()
Demonstrates the jQuery hide() method, hiding the
element with id="test".
• $("p").hide()
Demonstrates the jQuery hide() method, hiding all <p>
elements.
• $(".test").hide()
Demonstrates the jQuery hide() method, hiding all
elements with class="test".
Syntax
SELECT some HTML Elements and perform some action on them
$(selector).action()
Usually define functions only after the document is finished
loading, otherwise elements may not be there.
$(document).ready(function(){
// jQuery functions go here...
});
jQuery Selectors
• jQuery Element Selectors
• jQuery uses CSS selectors to select HTML
elements.
• $("p") selects all <p> elements.
• $("p.intro") selects all <p> elements with
class="intro".
• $("p#demo") selects all <p> elements with
id="demo".
• jQuery Attribute Selectors
• jQuery uses XPath expressions to select elements with
given attributes.
• $("[href]") select all elements with an href attribute.
• $("[href='#']") select all elements with an href value
equal to "#".
• $("[href!='#']") select all elements with an href
attribute NOT equal to "#".
• $("[href$='.jpg']") select all elements with an href
attribute that ends with ".jpg".
CSS Selectors
• jQuery CSS Selectors
– jQuery CSS selectors can be used to change CSS
properties for HTML elements.
– The following example changes the background-
color of all p elements to yellow:
• Example
• $("p").css("background-color","yellow");
More Examples
Syntax Description
$(this) Current HTML element
$("p") All <p> elements
$("p.intro") All <p> elements with class="intro"
$("p#intro") All <p> elements with id="intro"
$("p#intro:first") The first <p> element with id="intro"
$(".intro") All elements with class="intro"
$("#intro") The first element with id="intro"
$("ul li:first") The first <li> element of the first <ul>
$("ul li:first-child") The first <li> element of every <ul>
$(“ul li:nth-child(3)” The third <li> element of every <ul>
$("[href$='.jpg']") All elements with an href attribute that ends with
".jpg"
$("div#intro .head") All elements with class="head" inside a <div>
element with id="intro"
Event Functions
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body></html>
Sample Events
• Event Method Description
• $(document).ready(function) Binds a function to the ready event of a
document (when the document is finished loading)
• $(selector).click(function) Triggers, or binds a function to the click event
of selected elements
• $(selector).dblclick(function) Triggers, or binds a function to the double click
event of selected elements
• $(selector).focus(function) Triggers, or binds a function to the focus event
of selected elements
• $(selector).mouseover(function) Triggers, or binds a function to the mouseover
event of selected elements.
Effects
• Examples
• jQuery hide()
Demonstrates a simple jQuery hide() method.
• jQuery hide()
Another hide() demonstration. How to hide parts of
text.
• jQuery slideToggle()
Demonstrates a simple slide panel effect.
• jQuery fadeTo()
Demonstrates a simple jQuery fadeTo() method.
• jQuery animate()
Demonstrates a simple jQuery animate() method.
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();
});
Note: These can be very useful on mobile devices
Hide and show speed
• $(selector).hide(speed,callback)
• $(selector).show(speed,callback)
• $("button").click(function(){
$("p").hide(1000);
});
Toggle
Between show and hide
$(selector).toggle(speed,callback)
$("button").click(function(){
$("p").toggle();
});
jQuery Slide - slideDown, slideUp,
slideToggle
The jQuery slide methods gradually change the height for
selected elements.
jQuery has the following slide methods:
$(selector).slideDown(speed,callback)
$(selector).slideUp(speed,callback)
$(selector).slideToggle(speed,callback)
• The speed parameter can take the following values:
"slow", "fast", "normal", or milliseconds.
• The callback parameter is the name of a function to be
executed after the function completes.
Slide Examples
$(".flip").click(function(){
$(".panel").slideDown();
});
$(".flip").click(function(){
$(".panel").slideUp()
})
$(".flip").click(function(){
$(".panel").slideToggle();
});
• <html>
• <head>
• <script type="text/javascript" src="jquery.js"></script>
• <script type="text/javascript">
• $(document).ready(function(){
• $(".flip").click(function(){
• $(".panel").slideToggle("slow");
• });
• });
• </script>
•
• <style type="text/css">
• div.panel,p.flip
• {
• margin:0px;
• padding:5px;
• text-align:center;
• background:#e5eecc;
• border:solid 1px #c3c3c3;
• }
• div.panel
• {
• height:120px;
• display:none;
• }
• </style>
• </head>
•
• <body>
•
• <div class="panel">
• <p>Because time is valuable, we deliver quick and easy learning.</p>
• <p>At Stern, you can study everything you need to learn, in an accessible and handy format.</p>
• </div>
•
• <p class="flip">Show/Hide Panel</p>
•
• </body>
• </html>
jQuery Fade - fadeIn, fadeOut, fadeTo
• The jQuery fade methods gradually change the opacity for
selected elements.
• jQuery has the following fade methods:
• $(selector).fadeIn(speed,callback)
• $(selector).fadeOut(speed,callback)
• $(selector).fadeTo(speed,opacity,callback)
• The speed parameter can take the following values: "slow",
"fast", "normal", or milliseconds.
• The opacity parameter in the fadeTo() method allows
fading to a given opacity.
• The callback parameter is the name of a function to be
executed after the function completes.
Custom Animations
• The syntax of jQuery's method for making custom
animations is:
• $(selector).animate({params},[duration],[easing],
[callback])
• The key parameter is params. It defines the CSS
properties that will be animated. Many properties can
be animated at the same time:
animate({width:"70%",opacity:0.4,marginLeft:"0.6in",fontSize:"3em"})
;
• The second parameter is duration. It specifies the
speed of the animation. Possible values are "fast",
"slow", "normal", or milliseconds.
Animation Example
<script type="text/javascript"> $
(document).ready(function(){
$("button").click(function(){
$("div").animate({height:300},"slow");
$("div").animate({width:300},"slow");
$("div").animate({height:100},"slow");
$("div").animate({width:100},"slow");
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left:"100px"},"slow");
$("div").animate({fontSize:"3em"},"slow");
});
});
</script>
Callback Functions
Function called after action is completed
$("p").hide(1000,function(){
alert("The paragraph is now hidden");
});
Instead of
$("p").hide(1000);
alert("The paragraph is now hidden");
In 2nd
example the alert will show before the paragraph is hidden,
since the alert happens immediately and the hide takes 1
second. Calling the alert from a callback function ensures that it
won’t happen until the paragraph is hidden.
Changing HTML Content
$(selector).html(content)
The html() method changes the contents
(innerHTML) of matching HTML elements.
$("p").html(“Stern is the best");
Will change all html within a <p> tag to “Stern is
the best”
Example
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").html(“Stern is the best");
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>
Wait for
document to load
Add a button to change
All “p” elements to “Stern is the best”
When clicked.
Can also append or prepend content
Adding HTML content
$(selector).append(content)
• The append() method appends content to the
inside of matching HTML elements.
$(selector).prepend(content)
• The prepend() method "prepends" content to
the inside of matching HTML elements.
After and Before
$(selector).after(content)
The after() method inserts HTML content after
all matching elements.
$(selector).before(content)
The before() method inserts HTML content
before all matching elements.
Many, Many HTML functions
Look at full reference
CSS Methods
Method Description
addClass() Adds one or more classes to selected elements
css() Sets or returns one or more style properties for selected elements
hasClass() Checks if any of the selected elements have a specified class
height() Sets or returns the height of selected elements
offset() S ets or returns the position (relative to the document) for selected elements
offsetParent() Returns the first parent element that is positioned
position() Returns the position (relative to the parent element) of the first selected
element
removeClass() Removes one or more classes from selected elements
scrollLeft() Sets or returns the horizontal position of the scrollbar for the selected elements
scrollTop() Sets or returns the vertical position of the scrollbar for the selected elements
toggleClass() Toggles between adding/removing one or more classes from selected elements
width() Sets or returns the width of selected elements
jQuery AJAX
Asynchronous Javascript and XML
AJAX
Allows javascript to dynamically communicate with a server without
reloading the page.
jQuery provides a rich set of methods for AJAX web development.
With jQuery AJAX, you can request TXT, HTML, XML or JSON data from a
remote server using both HTTP Get and HTTP Post.
And you can load remote data directly into selected HTML elements of
your web page!
This is the magic that allows for web pages to dynamically change parts of
their content instead of having to reload the whole page. No more
click submit and wait for new page.
Example: Google Earth, Google maps
More map tiles are loaded in the background while you look at part of the
map, so that when you move, the next area is already loaded.
jQuery load method
The jQuery load() method is a simple (but very
powerful) AJAX function. It has the following
syntax:
$(selector).load(url,data,callback)
Use the selector to define the HTML element(s)
to change, and the url parameter to specify a
web address for your data.
jQuery load
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").load('test1.txt');
});
});
</script>
</head>
<body>
<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>
</body>
</html>
Load ‘test1.txt’ from same
Directory as the web page
And replace div content
With contents of “test1.txt”
jQuery AJAX
Many functions to move data back and forth
between the server and PARTS of the web
page.
Very powerful
Need these features to provide good user
experience on mobile devices
Conclusion
• jQuery provides a wide range of functionality that
makes very advanced capabilities available to
developers who know a little javascript, html and css.
• jQuery mobile extends those capabilities for mobile
devices by adding a set of mobile features
– Makes it easy(?) to develop cross platform mobile apps
that are fairly sophisticated without using the SDK tools
for the mobile device.
– jQuery mobile uses Phonegap to access mobile device
capabilities like geolocation, cameras, accelerometer, etc.
– jQuery mobile includes capabilities to use AJAX to move
data between the mobile device and a remote server.
– But next we do PHP.
QUESTIONS?

Más contenido relacionado

La actualidad más candente (20)

jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Jquery
JqueryJquery
Jquery
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
J query training
J query trainingJ query training
J query training
 
JQuery
JQueryJQuery
JQuery
 
J query lecture 1
J query lecture 1J query lecture 1
J query lecture 1
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery
jQueryjQuery
jQuery
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Jquery
JqueryJquery
Jquery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 

Destacado (20)

Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
Jms
JmsJms
Jms
 
Jms intro
Jms introJms intro
Jms intro
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
 
Css
CssCss
Css
 
Ajax
AjaxAjax
Ajax
 
Xpath
XpathXpath
Xpath
 
Intro to-ant
Intro to-antIntro to-ant
Intro to-ant
 
The spring framework
The spring frameworkThe spring framework
The spring framework
 
Presentation
PresentationPresentation
Presentation
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
 
Json
Json Json
Json
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Xslt
XsltXslt
Xslt
 
scala-intro
scala-introscala-intro
scala-intro
 
Rest introduction
Rest introductionRest introduction
Rest introduction
 
Facelets
FaceletsFacelets
Facelets
 
Groovygrails
GroovygrailsGroovygrails
Groovygrails
 
Jsp
JspJsp
Jsp
 

Similar a J query

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 BasicsEPAM Systems
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQueryLaila Buncab
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxAditiPawale1
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3luckysb16
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects WebStackAcademy
 
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
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tipsJack Franklin
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationSean Burgess
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Rakesh Jha
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
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
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxazz71
 

Similar a J query (20)

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
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
jQuery
jQueryjQuery
jQuery
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
jQuery besic
jQuery besicjQuery besic
jQuery besic
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
 
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...
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
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
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
Jquery library
Jquery libraryJquery library
Jquery library
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 

Más de Manav Prasad

Más de Manav Prasad (14)

Experience with mulesoft
Experience with mulesoftExperience with mulesoft
Experience with mulesoft
 
Mulesoftconnectors
MulesoftconnectorsMulesoftconnectors
Mulesoftconnectors
 
Mule and web services
Mule and web servicesMule and web services
Mule and web services
 
Mulesoft cloudhub
Mulesoft cloudhubMulesoft cloudhub
Mulesoft cloudhub
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Jpa
JpaJpa
Jpa
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Junit
JunitJunit
Junit
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Xhtml
XhtmlXhtml
Xhtml
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
 
Ant
AntAnt
Ant
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

J query

  • 1. jQuery A Javascript Library Hard things made eas(ier)
  • 2. jQuery • Javascript Library to do many, many things that would normally require intricate knowledge of javascript, different browsers, and different devices. • (Fairly) easy to learn • You should try all the examples on http://www.w3schools.com/jquery Or take the code Academy JQuery course. http://www.codeacademy.com
  • 3. Simple example Function which hides a <p> element when clicked <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $("p").click(function() { $(this).hide(); } ); } ); </script> </head> <body> <p>If you click on me, I will disappear.</p> </body> </html>
  • 4. jQuery Overview • What is jQuery? • jQuery is a library of JavaScript Functions. • jQuery is a lightweight "write less, do more" JavaScript library. • The jQuery library contains the following features: – HTML element selections – HTML element manipulation – CSS manipulation – HTML event functions – JavaScript Effects and animations – HTML DOM traversal and modification – AJAX – Utilities
  • 5. Using jQuery Just include the library <head> <script type="text/javascript" src="jquery.js"></script> </head>
  • 6. Simple jQuery Click button to hide all paragraphs <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me and things will be hidden</button> </body> </html>
  • 7. jQuery Syntax Examples $ indicates a jQuery statement (Note CSS Style References) • $(this).hide() Demonstrates the jQuery hide() method, hiding the current HTML element. • $("#test").hide() Demonstrates the jQuery hide() method, hiding the element with id="test". • $("p").hide() Demonstrates the jQuery hide() method, hiding all <p> elements. • $(".test").hide() Demonstrates the jQuery hide() method, hiding all elements with class="test".
  • 8. Syntax SELECT some HTML Elements and perform some action on them $(selector).action() Usually define functions only after the document is finished loading, otherwise elements may not be there. $(document).ready(function(){ // jQuery functions go here... });
  • 9. jQuery Selectors • jQuery Element Selectors • jQuery uses CSS selectors to select HTML elements. • $("p") selects all <p> elements. • $("p.intro") selects all <p> elements with class="intro". • $("p#demo") selects all <p> elements with id="demo".
  • 10. • jQuery Attribute Selectors • jQuery uses XPath expressions to select elements with given attributes. • $("[href]") select all elements with an href attribute. • $("[href='#']") select all elements with an href value equal to "#". • $("[href!='#']") select all elements with an href attribute NOT equal to "#". • $("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".
  • 11. CSS Selectors • jQuery CSS Selectors – jQuery CSS selectors can be used to change CSS properties for HTML elements. – The following example changes the background- color of all p elements to yellow: • Example • $("p").css("background-color","yellow");
  • 12. More Examples Syntax Description $(this) Current HTML element $("p") All <p> elements $("p.intro") All <p> elements with class="intro" $("p#intro") All <p> elements with id="intro" $("p#intro:first") The first <p> element with id="intro" $(".intro") All elements with class="intro" $("#intro") The first element with id="intro" $("ul li:first") The first <li> element of the first <ul> $("ul li:first-child") The first <li> element of every <ul> $(“ul li:nth-child(3)” The third <li> element of every <ul> $("[href$='.jpg']") All elements with an href attribute that ends with ".jpg" $("div#intro .head") All elements with class="head" inside a <div> element with id="intro"
  • 13. Event Functions <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body></html>
  • 14. Sample Events • Event Method Description • $(document).ready(function) Binds a function to the ready event of a document (when the document is finished loading) • $(selector).click(function) Triggers, or binds a function to the click event of selected elements • $(selector).dblclick(function) Triggers, or binds a function to the double click event of selected elements • $(selector).focus(function) Triggers, or binds a function to the focus event of selected elements • $(selector).mouseover(function) Triggers, or binds a function to the mouseover event of selected elements.
  • 15. Effects • Examples • jQuery hide() Demonstrates a simple jQuery hide() method. • jQuery hide() Another hide() demonstration. How to hide parts of text. • jQuery slideToggle() Demonstrates a simple slide panel effect. • jQuery fadeTo() Demonstrates a simple jQuery fadeTo() method. • jQuery animate() Demonstrates a simple jQuery animate() method.
  • 16. 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(); }); Note: These can be very useful on mobile devices
  • 17. Hide and show speed • $(selector).hide(speed,callback) • $(selector).show(speed,callback) • $("button").click(function(){ $("p").hide(1000); });
  • 18. Toggle Between show and hide $(selector).toggle(speed,callback) $("button").click(function(){ $("p").toggle(); });
  • 19. jQuery Slide - slideDown, slideUp, slideToggle The jQuery slide methods gradually change the height for selected elements. jQuery has the following slide methods: $(selector).slideDown(speed,callback) $(selector).slideUp(speed,callback) $(selector).slideToggle(speed,callback) • The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds. • The callback parameter is the name of a function to be executed after the function completes.
  • 21. • <html> • <head> • <script type="text/javascript" src="jquery.js"></script> • <script type="text/javascript"> • $(document).ready(function(){ • $(".flip").click(function(){ • $(".panel").slideToggle("slow"); • }); • }); • </script> • • <style type="text/css"> • div.panel,p.flip • { • margin:0px; • padding:5px; • text-align:center; • background:#e5eecc; • border:solid 1px #c3c3c3; • } • div.panel • { • height:120px; • display:none; • } • </style> • </head> • • <body> • • <div class="panel"> • <p>Because time is valuable, we deliver quick and easy learning.</p> • <p>At Stern, you can study everything you need to learn, in an accessible and handy format.</p> • </div> • • <p class="flip">Show/Hide Panel</p> • • </body> • </html>
  • 22. jQuery Fade - fadeIn, fadeOut, fadeTo • The jQuery fade methods gradually change the opacity for selected elements. • jQuery has the following fade methods: • $(selector).fadeIn(speed,callback) • $(selector).fadeOut(speed,callback) • $(selector).fadeTo(speed,opacity,callback) • The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds. • The opacity parameter in the fadeTo() method allows fading to a given opacity. • The callback parameter is the name of a function to be executed after the function completes.
  • 23. Custom Animations • The syntax of jQuery's method for making custom animations is: • $(selector).animate({params},[duration],[easing], [callback]) • The key parameter is params. It defines the CSS properties that will be animated. Many properties can be animated at the same time: animate({width:"70%",opacity:0.4,marginLeft:"0.6in",fontSize:"3em"}) ; • The second parameter is duration. It specifies the speed of the animation. Possible values are "fast", "slow", "normal", or milliseconds.
  • 24. Animation Example <script type="text/javascript"> $ (document).ready(function(){ $("button").click(function(){ $("div").animate({height:300},"slow"); $("div").animate({width:300},"slow"); $("div").animate({height:100},"slow"); $("div").animate({width:100},"slow"); }); }); </script>
  • 26. Callback Functions Function called after action is completed $("p").hide(1000,function(){ alert("The paragraph is now hidden"); }); Instead of $("p").hide(1000); alert("The paragraph is now hidden"); In 2nd example the alert will show before the paragraph is hidden, since the alert happens immediately and the hide takes 1 second. Calling the alert from a callback function ensures that it won’t happen until the paragraph is hidden.
  • 27. Changing HTML Content $(selector).html(content) The html() method changes the contents (innerHTML) of matching HTML elements. $("p").html(“Stern is the best"); Will change all html within a <p> tag to “Stern is the best”
  • 28. Example <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").html(“Stern is the best"); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body> </html> Wait for document to load Add a button to change All “p” elements to “Stern is the best” When clicked.
  • 29. Can also append or prepend content Adding HTML content $(selector).append(content) • The append() method appends content to the inside of matching HTML elements. $(selector).prepend(content) • The prepend() method "prepends" content to the inside of matching HTML elements.
  • 30. After and Before $(selector).after(content) The after() method inserts HTML content after all matching elements. $(selector).before(content) The before() method inserts HTML content before all matching elements.
  • 31. Many, Many HTML functions Look at full reference
  • 32. CSS Methods Method Description addClass() Adds one or more classes to selected elements css() Sets or returns one or more style properties for selected elements hasClass() Checks if any of the selected elements have a specified class height() Sets or returns the height of selected elements offset() S ets or returns the position (relative to the document) for selected elements offsetParent() Returns the first parent element that is positioned position() Returns the position (relative to the parent element) of the first selected element removeClass() Removes one or more classes from selected elements scrollLeft() Sets or returns the horizontal position of the scrollbar for the selected elements scrollTop() Sets or returns the vertical position of the scrollbar for the selected elements toggleClass() Toggles between adding/removing one or more classes from selected elements width() Sets or returns the width of selected elements
  • 33. jQuery AJAX Asynchronous Javascript and XML AJAX Allows javascript to dynamically communicate with a server without reloading the page. jQuery provides a rich set of methods for AJAX web development. With jQuery AJAX, you can request TXT, HTML, XML or JSON data from a remote server using both HTTP Get and HTTP Post. And you can load remote data directly into selected HTML elements of your web page! This is the magic that allows for web pages to dynamically change parts of their content instead of having to reload the whole page. No more click submit and wait for new page. Example: Google Earth, Google maps More map tiles are loaded in the background while you look at part of the map, so that when you move, the next area is already loaded.
  • 34. jQuery load method The jQuery load() method is a simple (but very powerful) AJAX function. It has the following syntax: $(selector).load(url,data,callback) Use the selector to define the HTML element(s) to change, and the url parameter to specify a web address for your data.
  • 35. jQuery load <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html> Load ‘test1.txt’ from same Directory as the web page And replace div content With contents of “test1.txt”
  • 36. jQuery AJAX Many functions to move data back and forth between the server and PARTS of the web page. Very powerful Need these features to provide good user experience on mobile devices
  • 37. Conclusion • jQuery provides a wide range of functionality that makes very advanced capabilities available to developers who know a little javascript, html and css. • jQuery mobile extends those capabilities for mobile devices by adding a set of mobile features – Makes it easy(?) to develop cross platform mobile apps that are fairly sophisticated without using the SDK tools for the mobile device. – jQuery mobile uses Phonegap to access mobile device capabilities like geolocation, cameras, accelerometer, etc. – jQuery mobile includes capabilities to use AJAX to move data between the mobile device and a remote server. – But next we do PHP.