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

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

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