SlideShare a Scribd company logo
1 of 31
Download to read offline
The jQuery
JavaScript Library
Hamid Zarrabi-Zadeh
Web Programming – Fall 2013
2

Outline
• Introduction
• Using jQuery
• DOM Manipulation

• jQuery Effects
• DOM Tree Traversal
• jQuery Utilities
3

What is jQuery?
• A light-weight JavaScript library designed to
simplify writing JavaScript code
• The most popular library in use today, used by
over 65% of the 10,000 most visited websites
• Major alternative libraries include
 Prototype
 MooTools
 YUI
 Ext JS
4

jQuery Features
• jQuery Main Functionalities
 DOM Manipulation
 Event Handling
 Effects
 AJAX
 Utilities
 Lots of plug-ins
5

jQuery Pros and Cons
• jQuery Pros
 write less, do more
 multi-browser support
 light-weight
 fast and optimized

• jQuery Cons
 load overhead
Using jQuery
7

Including jQuery
• To include jQuery, just load it into your page
<script src="jquery.js"></script>

• For a faster load, use minified and gzipped
version, from a content delivery network
<script src="http://ajax.googleapis.com/ajax/
libs/jquery/1.10.2/jquery.min.js"></script>
8

Usage Style
• With jQuery, we typically find (query) elements
and manipulate them
• Main usage style:
 $(selector).action();

• Examples
$('p').hide();
$(document).ready(function() {
// main code
})
9

Chaining
• The output of $() function is a jQuery object
• jQuery actions are chainable, as they usually
return a jQuery object

$('img').addClass('test').hide();
10

Selectors
• jQuery uses CSS-like selectors
• We can select elements by tag name, id, class,
attributes, etc.
$('p')
$('#id')
$('.class')
$('parent > child')
$('[attr="value"]')
$('p:first')
$('tr:odd')
$(':button')
$(document.body)
11

Events
• With jQuery, we can easily attach handlers to
events
$('p').click(function() {
$(this).hide();
});

$('p').on('click', function() { ... });
DOM Manipulation
13

Get/Set Content
• jQuery methods for DOM manipulation include
 text()
 html()
 val()
alert($('p').text());
$('p').html('Hello!');
14

Attributes
• You can get/set element attributes by attr()
method
alert($('p').attr('title'));
$('p').attr('title', 'Test');
$('a').attr({
title: 'Test',
href: 'http://example.com'
})
15

Styles
• jQuery methods for CSS manipulation include
 addClass()
 removeClass()
 toggleClass()
 css()
$('p').addClass('active').css('color', 'blue');
$('p').css('color');

// returns blue
16

Dimensions
• jQuery has the following dimension methods
 width()
 height()
 innerWidth()
 innerHeight()
 outerWidth()
 outerHeight()
jQuery Effects
18

jQuery Effects
• jQuery provides methods for basic effects,
including
 hide and show
 fade
 slide
 animate!
19

Hide/Show
• We can hide/show elements by hide(), show()
and toggle() methods
$('p').click(function() {
$(this).hide();
});

• The methods accept optional speed and
callback parameters
$('p').hide(1000, function() {
$(this).show();
});
20

Fading
• jQuery has the following fading methods
 fadeIn()
 fadeOut()
 fadeToggle()
 fadeTo()

• All with optional speed and callback parameters
$('p').fadeOut();
$('p').fadeOut(1000);
$('p').fadeOut('slow');
$('p').fadeTo(1000, .3);
21

Sliding
• The following sliding methods are available
 slideDown()
 slideUp()
 slideToggle()

• With optional speed and callback parameters
$('p').slideUp();
$('p').slideDown(1000);
22

Animation
• Custom animations can be created with
animate() function
$('p').click(function(){
$(this).animate({height: '200px'}, 'slow');
})

• You can change several styles at once
• animations are queued
DOM Tree Traversal
24

Parents
• We can access parents of an element using:
 parent()
 parents()
 parentsUntil()
 closest()
$('p').parents();
$('p').parentsUntil('div');
25

Children
• We can access children of an element using:
 children()
 find()
$('p').children();
$('p').find('span');
26

Siblings
• We can access siblings of an element using:
 siblings()
 next()
 nextAll()
 nextUntil()
 prev()
 prevAll()
 prevUntil()
27

Filtering
• Filtering methods
 first()
 last()
 eq()
 filter()
 not()
$('p').first()
$('p').eq(2)

// the 3rd <p> element

$('p').filter('.highlight')
$('p').not(':selected')
jQuery Utilities
29

Each
• The each() method iterates over a jQuery object
and executes a function for each element
$('li').each(function(index) {
$(this).attr('title', 'Item '+ index);
});

• You can use $.each() to iterate over arrays and
collections
$.each([2, 4, 16], function(index, value) {
alert(index + ': ' + value);
});
30

Extend
• The $.extend() method is used to merge the
contents of two or more objects
 $.extend(target [, object1 ] [, objectN ])
var object = $.extend({}, object1, object2);
function test(params) {
var defaults = { ... };
$.extend(defaults, params);
...
}
31

References
• jQuery API Documentation
 http://api.jquery.com

• W3Schools
 http://www.w3schools.com/jquery

More Related Content

What's hot

What's hot (20)

D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery
jQueryjQuery
jQuery
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
 
Jquery
JqueryJquery
Jquery
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQuery
jQueryjQuery
jQuery
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 

Viewers also liked

Viewers also liked (7)

Marking the discourse
Marking the discourseMarking the discourse
Marking the discourse
 
Achieve correct word choice
Achieve correct word choiceAchieve correct word choice
Achieve correct word choice
 
Steps of printing a paragraph
Steps of printing a paragraphSteps of printing a paragraph
Steps of printing a paragraph
 
Surface revision
Surface revisionSurface revision
Surface revision
 
Traits good critical writer
Traits good critical writerTraits good critical writer
Traits good critical writer
 
Texas
TexasTexas
Texas
 
المخلفات الطبية الخطره
المخلفات الطبية الخطرهالمخلفات الطبية الخطره
المخلفات الطبية الخطره
 

Similar to jQuery JavaScript Library Introduction

J query presentation
J query presentationJ query presentation
J query presentationakanksha17
 
J query presentation
J query presentationJ query presentation
J query presentationsawarkar17
 
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
 
JQuery Comprehensive Overview
JQuery Comprehensive OverviewJQuery Comprehensive Overview
JQuery Comprehensive OverviewMohamed Loey
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesMark Roden
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayCodecademy Ren
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQueryAnil Kumar
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile IntroGonzalo Parra
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaEdureka!
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - IntroductionWebStackAcademy
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobileErik Duval
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MySteve McMahon
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
Intro to jQuery for Drupal
Intro to jQuery for DrupalIntro to jQuery for Drupal
Intro to jQuery for Drupaljhamiltoorion
 

Similar to jQuery JavaScript Library Introduction (20)

JQuery UI
JQuery UIJQuery UI
JQuery UI
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query
J queryJ query
J query
 
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
 
JQuery Comprehensive Overview
JQuery Comprehensive OverviewJQuery Comprehensive Overview
JQuery Comprehensive Overview
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ay
 
Jquery
JqueryJquery
Jquery
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | Edureka
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Intro to jQuery for Drupal
Intro to jQuery for DrupalIntro to jQuery for Drupal
Intro to jQuery for Drupal
 
J query module1
J query module1J query module1
J query module1
 

More from Ibrahem Abdel Ghany

الدايوكسينات Dioxins
الدايوكسينات Dioxinsالدايوكسينات Dioxins
الدايوكسينات DioxinsIbrahem Abdel Ghany
 
How can you start a conversation when you have nothing to talk
How can you start a conversation when you have nothing to talkHow can you start a conversation when you have nothing to talk
How can you start a conversation when you have nothing to talkIbrahem Abdel Ghany
 
Most common weak forms in english
Most common weak forms in englishMost common weak forms in english
Most common weak forms in englishIbrahem Abdel Ghany
 
To summarize a paragraph you should
To summarize a paragraph you shouldTo summarize a paragraph you should
To summarize a paragraph you shouldIbrahem Abdel Ghany
 
Steps for writing an informal e mail
Steps for writing an informal e mailSteps for writing an informal e mail
Steps for writing an informal e mailIbrahem Abdel Ghany
 
Steps for writing a formal e mail
Steps for writing a formal e mailSteps for writing a formal e mail
Steps for writing a formal e mailIbrahem Abdel Ghany
 
Steps of writing an informal letter
Steps of writing an informal letterSteps of writing an informal letter
Steps of writing an informal letterIbrahem Abdel Ghany
 
Components of proofreading checklist of a paragraph
Components of proofreading checklist of a paragraphComponents of proofreading checklist of a paragraph
Components of proofreading checklist of a paragraphIbrahem Abdel Ghany
 
Steps of proofreading a paragraph
Steps of proofreading a paragraphSteps of proofreading a paragraph
Steps of proofreading a paragraphIbrahem Abdel Ghany
 
Strategies for successful word choice
Strategies for successful word choiceStrategies for successful word choice
Strategies for successful word choiceIbrahem Abdel Ghany
 

More from Ibrahem Abdel Ghany (20)

الدايوكسينات Dioxins
الدايوكسينات Dioxinsالدايوكسينات Dioxins
الدايوكسينات Dioxins
 
How can you start a conversation when you have nothing to talk
How can you start a conversation when you have nothing to talkHow can you start a conversation when you have nothing to talk
How can you start a conversation when you have nothing to talk
 
Most common weak forms in english
Most common weak forms in englishMost common weak forms in english
Most common weak forms in english
 
To summarize a paragraph you should
To summarize a paragraph you shouldTo summarize a paragraph you should
To summarize a paragraph you should
 
Steps for writing an informal e mail
Steps for writing an informal e mailSteps for writing an informal e mail
Steps for writing an informal e mail
 
Steps for writing a formal e mail
Steps for writing a formal e mailSteps for writing a formal e mail
Steps for writing a formal e mail
 
Example of a unified paragraph
Example of a unified paragraphExample of a unified paragraph
Example of a unified paragraph
 
Steps of writing an informal letter
Steps of writing an informal letterSteps of writing an informal letter
Steps of writing an informal letter
 
Steps of editing a paragraph
Steps of editing a paragraphSteps of editing a paragraph
Steps of editing a paragraph
 
Components of proofreading checklist of a paragraph
Components of proofreading checklist of a paragraphComponents of proofreading checklist of a paragraph
Components of proofreading checklist of a paragraph
 
Steps of proofreading a paragraph
Steps of proofreading a paragraphSteps of proofreading a paragraph
Steps of proofreading a paragraph
 
Global revision
Global revisionGlobal revision
Global revision
 
Surface revising strategies
Surface revising strategiesSurface revising strategies
Surface revising strategies
 
Steps of writing a draft
Steps of writing a draftSteps of writing a draft
Steps of writing a draft
 
Word order
Word orderWord order
Word order
 
Steps for paragraph writing
Steps for paragraph writingSteps for paragraph writing
Steps for paragraph writing
 
Six pre writing steps
Six pre writing stepsSix pre writing steps
Six pre writing steps
 
Strategies for successful word choice
Strategies for successful word choiceStrategies for successful word choice
Strategies for successful word choice
 
Tools of critical reading
Tools of critical readingTools of critical reading
Tools of critical reading
 
Bias
BiasBias
Bias
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 

jQuery JavaScript Library Introduction

  • 1. The jQuery JavaScript Library Hamid Zarrabi-Zadeh Web Programming – Fall 2013
  • 2. 2 Outline • Introduction • Using jQuery • DOM Manipulation • jQuery Effects • DOM Tree Traversal • jQuery Utilities
  • 3. 3 What is jQuery? • A light-weight JavaScript library designed to simplify writing JavaScript code • The most popular library in use today, used by over 65% of the 10,000 most visited websites • Major alternative libraries include  Prototype  MooTools  YUI  Ext JS
  • 4. 4 jQuery Features • jQuery Main Functionalities  DOM Manipulation  Event Handling  Effects  AJAX  Utilities  Lots of plug-ins
  • 5. 5 jQuery Pros and Cons • jQuery Pros  write less, do more  multi-browser support  light-weight  fast and optimized • jQuery Cons  load overhead
  • 7. 7 Including jQuery • To include jQuery, just load it into your page <script src="jquery.js"></script> • For a faster load, use minified and gzipped version, from a content delivery network <script src="http://ajax.googleapis.com/ajax/ libs/jquery/1.10.2/jquery.min.js"></script>
  • 8. 8 Usage Style • With jQuery, we typically find (query) elements and manipulate them • Main usage style:  $(selector).action(); • Examples $('p').hide(); $(document).ready(function() { // main code })
  • 9. 9 Chaining • The output of $() function is a jQuery object • jQuery actions are chainable, as they usually return a jQuery object $('img').addClass('test').hide();
  • 10. 10 Selectors • jQuery uses CSS-like selectors • We can select elements by tag name, id, class, attributes, etc. $('p') $('#id') $('.class') $('parent > child') $('[attr="value"]') $('p:first') $('tr:odd') $(':button') $(document.body)
  • 11. 11 Events • With jQuery, we can easily attach handlers to events $('p').click(function() { $(this).hide(); }); $('p').on('click', function() { ... });
  • 13. 13 Get/Set Content • jQuery methods for DOM manipulation include  text()  html()  val() alert($('p').text()); $('p').html('Hello!');
  • 14. 14 Attributes • You can get/set element attributes by attr() method alert($('p').attr('title')); $('p').attr('title', 'Test'); $('a').attr({ title: 'Test', href: 'http://example.com' })
  • 15. 15 Styles • jQuery methods for CSS manipulation include  addClass()  removeClass()  toggleClass()  css() $('p').addClass('active').css('color', 'blue'); $('p').css('color'); // returns blue
  • 16. 16 Dimensions • jQuery has the following dimension methods  width()  height()  innerWidth()  innerHeight()  outerWidth()  outerHeight()
  • 18. 18 jQuery Effects • jQuery provides methods for basic effects, including  hide and show  fade  slide  animate!
  • 19. 19 Hide/Show • We can hide/show elements by hide(), show() and toggle() methods $('p').click(function() { $(this).hide(); }); • The methods accept optional speed and callback parameters $('p').hide(1000, function() { $(this).show(); });
  • 20. 20 Fading • jQuery has the following fading methods  fadeIn()  fadeOut()  fadeToggle()  fadeTo() • All with optional speed and callback parameters $('p').fadeOut(); $('p').fadeOut(1000); $('p').fadeOut('slow'); $('p').fadeTo(1000, .3);
  • 21. 21 Sliding • The following sliding methods are available  slideDown()  slideUp()  slideToggle() • With optional speed and callback parameters $('p').slideUp(); $('p').slideDown(1000);
  • 22. 22 Animation • Custom animations can be created with animate() function $('p').click(function(){ $(this).animate({height: '200px'}, 'slow'); }) • You can change several styles at once • animations are queued
  • 24. 24 Parents • We can access parents of an element using:  parent()  parents()  parentsUntil()  closest() $('p').parents(); $('p').parentsUntil('div');
  • 25. 25 Children • We can access children of an element using:  children()  find() $('p').children(); $('p').find('span');
  • 26. 26 Siblings • We can access siblings of an element using:  siblings()  next()  nextAll()  nextUntil()  prev()  prevAll()  prevUntil()
  • 27. 27 Filtering • Filtering methods  first()  last()  eq()  filter()  not() $('p').first() $('p').eq(2) // the 3rd <p> element $('p').filter('.highlight') $('p').not(':selected')
  • 29. 29 Each • The each() method iterates over a jQuery object and executes a function for each element $('li').each(function(index) { $(this).attr('title', 'Item '+ index); }); • You can use $.each() to iterate over arrays and collections $.each([2, 4, 16], function(index, value) { alert(index + ': ' + value); });
  • 30. 30 Extend • The $.extend() method is used to merge the contents of two or more objects  $.extend(target [, object1 ] [, objectN ]) var object = $.extend({}, object1, object2); function test(params) { var defaults = { ... }; $.extend(defaults, params); ... }
  • 31. 31 References • jQuery API Documentation  http://api.jquery.com • W3Schools  http://www.w3schools.com/jquery