SlideShare a Scribd company logo
- I W I L L S T U D Y . C O M
jQuery Basics
hide()
 $("#hide").click(function(){
$("p").hide();
});
 $("button").click(function(){
$("p").hide(1000);
});
"slow", "fast
", or
milliseconds
.
show()
 $("#show").click(function(){
$("p").show();
});
toggle()
 $("button").click(function(){
$("p").toggle();
});
 $(selector).toggle(speed,callback);
 The optional callback parameter is a function to be
executed after toggle() completes.
jQuery Effects - Fading
 With jQuery you can fade an element in and out of
visibility.
 jQuery has the following fade methods:
 fadeIn()
 fadeOut()
 fadeToggle()
 fadeTo()
fadeIn()
 $("button").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
 The jQuery fadeIn() method is used to fade in a
hidden element.
fadeOut()
 $("button").click(function(){
$("#div1").fadeOut();
$("#div2").fadeOut("slow");
$("#div3").fadeOut(3000);
});
 The jQuery fadeOut() method is used to fade out a
visible element.
fadeToggle()
 $("button").click(function(){
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
});
 The jQuery fadeToggle() method toggles between the
fadeIn() and fadeOut() methods.
fadeTo()
 The jQuery fadeTo() method allows fading to a given
opacity (value between 0 and 1).
 $("button").click(function(){
$("#div1").fadeTo("slow",0.15);
$("#div2").fadeTo("slow",0.4);
$("#div3").fadeTo("slow",0.7);
});
jQuery Effects - Sliding
 With jQuery you can create a sliding effect on
elements.
 jQuery has the following slide methods:
 slideDown()
 slideUp()
 slideToggle()
slideDown()
 $("#flip").click(function(){
$("#panel").slideDown();
});
 The jQuery slideDown() method is used to slide
down an element.
slideUp()
 $("#flip").click(function(){
$("#panel").slideUp();
});
 The jQuery slideUp() method is used to slide up an
element.
slideToggle()
 $("#flip").click(function(){
$("#panel").slideToggle();
});
 The jQuery slideToggle() method toggles between
the slideDown() and slideUp() methods.
jQuery Animations
 The jQuery animate() method lets you create custom
animations.
 $(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.
animate()
 $("button").click(function(){
$("div").animate({left:‘450px'});
});
 Example demonstrates a simple use of the animate()
method; it moves a <div> element to the left, until it
has reached a left property of 450px:
animate() – Manipulate Multiple Properties
 $("button").click(function(){
$("div").animate({
left:'250px',
opacity:'0.5',
height:'150px',
width:'150px'
});
});
animate() – Using Relative Properties
 $("button").click(function(){
$("div").animate({
left:'250px',
height:'+=150px',
width:'+=150px'
});
});
animate() – Using Pre-defined values
 $("button").click(function(){
$("div").animate({
height:'toggle'
});
});
animate() – Using Queue Functionality
 $("button").click(function(){
var div=$("div");
div.animate({height:'300px',opacity:'0.4'},"slow
");
div.animate({width:'300px',opacity:'0.8'},"slow"
);
div.animate({height:'100px',opacity:'0.4'},"slow"
);
div.animate({width:'100px',opacity:'0.8'},"slow"
);
});
 if you write multiple animate() calls after each
other, jQuery creates an "internal" queue with
jQuery – Stop animation
 The jQuery stop() method is used to stop animations
or effects before it is finished.
 The stop() method works for all jQuery effect
functions, including sliding, fading and custom
animations.
 $("#stop").click(function(){
$("#panel").stop();
});
jQuery – Stop animation
 $(selector).stop(stopAll,goToEnd);
 The optional stopAll parameter specifies whether
also the animation queue should be cleared or not.
Default is false, which means that only the active
animation will be stopped, allowing any queued
animations to be performed afterwards.
 The optional goToEnd parameter specifies whether
or not to complete the current animation
immediately. Default is false.
 So, by default, the stop() method kills the current
animation being performed on the selected element.
jQuery – Callback Function
 IMPORTANT
 JavaScript statements are executed line by line. However, with
effects, the next line of code can be run even though the effect
is not finished. This can create errors.
 To prevent this, you can create a callback function.
 A callback function is executed after the current effect is
finished.
 Typical syntax: $(selector).hide(speed,callback);
Callback Function - Example
 Correct
 $("button").click(function(){
$("p").hide("slow",function(){
alert("The paragraph is now hidden");
});
});
 Incorrect
 $("button").click(function(){
$("p").hide(1000);
alert("The paragraph is now hidden");
});
jQuery Chaining
 We have been writing jQuery statements one at a
time (one after the other).
 However, there is a technique called chaining, that
allows us to run multiple jQuery commands, one
after the other, on the same element(s).
jQuery Chaining Example
 Following example chains together the
css(), slideUp(), and slideDown() methods. The "p1"
element first changes to red, then it slides up, and
then it slides down
 $("#p1").css("color","red").slideUp(2000).slideDown(2000);
 Or
 $("#p1").css("color","red")
.slideUp(2000)
.slideDown(2000);
jQuery GET Content
 Get Content - text(), html(), and val()
 Three simple, but useful, jQuery methods for DOM
manipulation are:
 text() - Sets or returns the text content of selected
elements
 html() - Sets or returns the content of selected
elements (including HTML markup)
 val() - Sets or returns the value of form fields
jQuery text() & html()
 $("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
val() and attr()
 $("#btn1").click(function(){
alert("Value: " + $("#test").val());
});
 $("button").click(function(){
alert($("#w3s").attr("href"));
});
Set & Get Attributes
 $("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});
Thanks
 References: w3schools.com and Google

More Related Content

What's hot (20)

PDF
Slide
jay li
 
PDF
Epic South Disasters
Christopher Adams
 
PPTX
JQuery
SelmanJagxhiu
 
PDF
CQRS and Event Sourcing in a Symfony application
Samuel ROZE
 
PDF
Redux Sagas - React Alicante
Ignacio Martín
 
PDF
Go Beast Mode with Realtime Reactive Interfaces in Angular 2 and Firebase
Lukas Ruebbelke
 
PDF
Shibuya.js Lightning Talks
jeresig
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PDF
Webgl para JavaScripters
gerbille
 
PDF
Prototype UI
Sébastien Gruhier
 
PDF
Designing Immutability Data Flows in Ember
Jorge Lainfiesta
 
KEY
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Vagmi Mudumbai
 
KEY
amsterdamjs - jQuery 1.5
mennovanslooten
 
PPTX
The redux saga begins
Daniel Franz
 
PDF
Processing and Processing.js
jeresig
 
PDF
Prototype & jQuery
Remy Sharp
 
PPTX
Less ismorewithcoffeescript webdirectionsfeb2012
Jo Cranford
 
PDF
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
彼得潘 Pan
 
PDF
Functionality Focused Code Organization
Rebecca Murphey
 
PDF
The Dom Scripting Toolkit J Query
QConLondon2008
 
Slide
jay li
 
Epic South Disasters
Christopher Adams
 
CQRS and Event Sourcing in a Symfony application
Samuel ROZE
 
Redux Sagas - React Alicante
Ignacio Martín
 
Go Beast Mode with Realtime Reactive Interfaces in Angular 2 and Firebase
Lukas Ruebbelke
 
Shibuya.js Lightning Talks
jeresig
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Webgl para JavaScripters
gerbille
 
Prototype UI
Sébastien Gruhier
 
Designing Immutability Data Flows in Ember
Jorge Lainfiesta
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Vagmi Mudumbai
 
amsterdamjs - jQuery 1.5
mennovanslooten
 
The redux saga begins
Daniel Franz
 
Processing and Processing.js
jeresig
 
Prototype & jQuery
Remy Sharp
 
Less ismorewithcoffeescript webdirectionsfeb2012
Jo Cranford
 
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
彼得潘 Pan
 
Functionality Focused Code Organization
Rebecca Murphey
 
The Dom Scripting Toolkit J Query
QConLondon2008
 

Viewers also liked (18)

PDF
Cloud Computing
NAILBITER
 
PPTX
Social Media Strategies
NAILBITER
 
PDF
Cloud Workshop - Presentation
NAILBITER
 
PPTX
iWillStudy.com - Light Pitch
NAILBITER
 
PPTX
GBGahmedabad - Create your Business Website
NAILBITER
 
PPTX
Cloud Summit Ahmedabad
NAILBITER
 
PPTX
Mapathon 2013 - Google Maps Javascript API
NAILBITER
 
PPTX
JQuery - Effect - Animate method
Pathomchon Sriwilairit
 
PPTX
Jquery parte 1
Cesar Eduardo Suarez T
 
PDF
Frameworks y herramientas de desarrollo ágil para emprendedores y startups
Mario Jose Villamizar Cano
 
PDF
Programacion web
Carlos Alonso Pérez
 
PPTX
Bootstrap [part 1]
Ghanshyam Patel
 
PDF
Atix19
Esteban Saavedra
 
PDF
ATIX09
Esteban Saavedra
 
PDF
Seguridad Sistemas de Gobierno
Esteban Saavedra
 
PDF
Tunneling: Esquivando Restricciones de Proxies y Firewalls
Esteban Saavedra
 
PDF
Lineas Base Migracion a Software Libre
Esteban Saavedra
 
PDF
Frameworks para desarrollo de aplicaciones Web
Esteban Saavedra
 
Cloud Computing
NAILBITER
 
Social Media Strategies
NAILBITER
 
Cloud Workshop - Presentation
NAILBITER
 
iWillStudy.com - Light Pitch
NAILBITER
 
GBGahmedabad - Create your Business Website
NAILBITER
 
Cloud Summit Ahmedabad
NAILBITER
 
Mapathon 2013 - Google Maps Javascript API
NAILBITER
 
JQuery - Effect - Animate method
Pathomchon Sriwilairit
 
Jquery parte 1
Cesar Eduardo Suarez T
 
Frameworks y herramientas de desarrollo ágil para emprendedores y startups
Mario Jose Villamizar Cano
 
Programacion web
Carlos Alonso Pérez
 
Bootstrap [part 1]
Ghanshyam Patel
 
Seguridad Sistemas de Gobierno
Esteban Saavedra
 
Tunneling: Esquivando Restricciones de Proxies y Firewalls
Esteban Saavedra
 
Lineas Base Migracion a Software Libre
Esteban Saavedra
 
Frameworks para desarrollo de aplicaciones Web
Esteban Saavedra
 
Ad

Similar to jQuery for Beginners (20)

PPTX
presentation_jquery_ppt.pptx
azz71
 
PPT
J query
Manav Prasad
 
PDF
jQuery - Chapter 3 - Effects
WebStackAcademy
 
PPTX
JQuery_and_Ajax.pptx
AditiPawale1
 
PPT
14709302.ppt
SunilChaluvaiah
 
PDF
jQuery Effects
Adelon Zeta
 
PPTX
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
PPT
J query presentation
sawarkar17
 
PPT
J query presentation
akanksha17
 
PPTX
Getting started with jQuery
Gill Cleeren
 
PDF
Jquery presentation
Mevin Mohan
 
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
PPTX
jQuery besic
Syeful Islam
 
PDF
Introduzione JQuery
orestJump
 
PDF
Introduction to jQuery
Seble Nigussie
 
PPTX
jQuery basics for Beginners
Pooja Saxena
 
PPTX
A to Z about JQuery - Become Newbie to Expert Java Developer
Manoj Bhuva
 
PPSX
JQuery Comprehensive Overview
Mohamed Loey
 
presentation_jquery_ppt.pptx
azz71
 
J query
Manav Prasad
 
jQuery - Chapter 3 - Effects
WebStackAcademy
 
JQuery_and_Ajax.pptx
AditiPawale1
 
14709302.ppt
SunilChaluvaiah
 
jQuery Effects
Adelon Zeta
 
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
J query presentation
sawarkar17
 
J query presentation
akanksha17
 
Getting started with jQuery
Gill Cleeren
 
Jquery presentation
Mevin Mohan
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
jQuery besic
Syeful Islam
 
Introduzione JQuery
orestJump
 
Introduction to jQuery
Seble Nigussie
 
jQuery basics for Beginners
Pooja Saxena
 
A to Z about JQuery - Become Newbie to Expert Java Developer
Manoj Bhuva
 
JQuery Comprehensive Overview
Mohamed Loey
 
Ad

More from NAILBITER (20)

PPTX
Android Fundamentals & Figures of 2012
NAILBITER
 
PPTX
The iPhone development on windows
NAILBITER
 
PDF
Ambastha EduTech Pvt Ltd
NAILBITER
 
PPTX
Branding
NAILBITER
 
PPTX
Advertising
NAILBITER
 
PPTX
Develop open source search engine
NAILBITER
 
PDF
Location based solutions maps & your location
NAILBITER
 
PDF
Html5 workshop part 1
NAILBITER
 
PDF
Android Workshop - Session 2
NAILBITER
 
PDF
Android Workshop Session 1
NAILBITER
 
PDF
Linux Seminar for Beginners
NAILBITER
 
PDF
Linux advanced concepts - Part 2
NAILBITER
 
PDF
Linux advanced concepts - Part 1
NAILBITER
 
PDF
Linux concepts
NAILBITER
 
PDF
Linux basics
NAILBITER
 
PDF
Career-Edge Magazine coverage - Ritesh Ambastha
NAILBITER
 
PDF
Ubuntu Workshop Kit - Study Material
NAILBITER
 
PDF
Android Workshop Presentation
NAILBITER
 
PDF
Social media part 1
NAILBITER
 
PDF
Social media part 2
NAILBITER
 
Android Fundamentals & Figures of 2012
NAILBITER
 
The iPhone development on windows
NAILBITER
 
Ambastha EduTech Pvt Ltd
NAILBITER
 
Branding
NAILBITER
 
Advertising
NAILBITER
 
Develop open source search engine
NAILBITER
 
Location based solutions maps & your location
NAILBITER
 
Html5 workshop part 1
NAILBITER
 
Android Workshop - Session 2
NAILBITER
 
Android Workshop Session 1
NAILBITER
 
Linux Seminar for Beginners
NAILBITER
 
Linux advanced concepts - Part 2
NAILBITER
 
Linux advanced concepts - Part 1
NAILBITER
 
Linux concepts
NAILBITER
 
Linux basics
NAILBITER
 
Career-Edge Magazine coverage - Ritesh Ambastha
NAILBITER
 
Ubuntu Workshop Kit - Study Material
NAILBITER
 
Android Workshop Presentation
NAILBITER
 
Social media part 1
NAILBITER
 
Social media part 2
NAILBITER
 

Recently uploaded (20)

PPTX
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PPTX
How to Add New Item in CogMenu in Odoo 18
Celine George
 
PPTX
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
How to Add New Item in CogMenu in Odoo 18
Celine George
 
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 

jQuery for Beginners