SlideShare a Scribd company logo
1 of 54
Download to read offline
Richard D. Worth, jQuery Team
http://twitter.com/rworth
Open Source (MIT, GPL)
JavaScript Library
Richard D. Worth
John Resig, Author
Mozilla, JavaScript Evangelist
http://ejohn.org/
January 2006
BarCampNYC
History
Richard D. Worth
Minimal
Lightweight (19kb)
Unobtrusive
Richard D. Worth
Browser Compatible
IE6+
Safari 3+
Chrome
FF2+
Opera 9+
Richard D. Worth
reddit.com
espn.com
ibm.com
boxee.tv
bit.ly
twitpic.com
whitehouse.gov
microsoft.com
amazon.com
netflix.com
stackoverflow.com
bing.com
monster.com
tv.com
overstock.com
time.com
capitalone.com
wordpress.com
dell.com
twitter.com
w3.org
Who’s Using jQuery
Richard D. Worth
reddit.com
ddit.c
espn.com
n.com
ibm.com
i m
oxee.tv
boxe
bi
bit.ly
twitpic.com
whitehouse.gov
microsoft.com
c
amazon.com
am
netflix.com
bing.com
monster.com
tv.com
overstock.com
time.com
capitalone.com
wordpress.com
dell.com
twitter.com
w3.org
Who’s Using jQuery
Richard D. Worth
stackoverflow.com
Changes the way
you write
JavaScript
Richard D. Worth
var tables = document.getElementsByTagName('table');
for (var t = 0; t < tables.length; t++) {
var rows = tables[t].getElementsByTagName('tr');
for (var i = 1; i < rows.length; i += 2) {
if (!/(^|s)odd(s|$)/.test(rows[i].className)) {
rows[i].className += ' odd';
}
}
}
Richard D. Worth
jQuery('table tr:nth-child(odd)')
.addClass('odd');
Richard D. Worth
$ == jQuery
jQuery $ Alias
Richard D. Worth
jQuery Pattern
Find Things
Do Stuff
Richard D. Worth
$( )
. ();
jQuery Pattern
Find Things
Do Stuff
Richard D. Worth
$("div").hide();
$("button").remove();
$("form").submit();
$("p").addClass("special");
$("span").show("fast");
Richard D. Worth
<!DOCTYPE html><html><body>
<ul>
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul>
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul>
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul');
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li><a>home</a></li>
<li><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li');
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a>home</a></li>
<li class="item"><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li').addClass('item');
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a>home</a></li>
<li class="item"><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li').addClass('item');
jQuery('#nav a');
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a>home</a></li>
<li class="item"><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li').addClass('item');
jQuery('#nav a').each(function(){
jQuery(this);
});
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a>home</a></li>
<li class="item"><a>about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li').addClass('item');
jQuery('#nav a').each(function(){
jQuery(this);
});
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a href="/home">home</a></li>
<li class="item"><a href="/about">about</a></li>
</ul>
<script src="jquery.js"></script><script>
jQuery('ul').attr('id', 'nav');
jQuery('#nav li').addClass('item');
jQuery('#nav a').each(function(){
jQuery(this).attr('href', '/' + jQuery(this).text());
});
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a href="/home">home</a></li>
<li class="item"><a href="/about">about</a></li>
</ul>
<script src="jquery.js"></script><script>
$('ul').attr('id', 'nav');
$('#nav li').addClass('item');
$('#nav a').each(function(){
$(this).attr('href', '/' + $(this).text());
});
</script>
</body></html>
Richard D. Worth
<!DOCTYPE html><html><body>
<ul id="nav">
<li class="item"><a href="/home">home</a></li>
<li class="item"><a href="/about">about</a></li>
</ul>
<script src="jquery.js"></script><script>
$('ul').attr('id', 'nav');
$('#nav li').addClass('item').find('a').each(function(){
$(this).attr('href', '/' + $(this).text());
});
</script>
</body></html>
Richard D. Worth
jQuery Object
Collection of DOM Elements
Array-like
Holds the methods
Richard D. Worth
Selectors
CSS 1-3 (better than most browsers)
Basic XPath via a plugin
Custom jQuery selectors
Richard D. Worth
$("div#nav")
$("form > table")
$("tr:even")
$("a strong")
$("a[href^=https://]")
Richard D. Worth
$(":hidden")
$("ul:visible")
$(":disabled")
$("td:first *")
$("fieldset:has(button)")
Richard D. Worth
Method Calls
Safe (0, 1, more elements)
No need for loop
Some operate on first element
Richard D. Worth
$("p").addClass("special")
.css("color", "red")
.append("hello")
.show("slow");
Chaining
Richard D. Worth
Some methods modify chain
.end() to get back to previous
Most methods are chainable
Chaining
Richard D. Worth
Concise, Natural, Consistent
Logical, Almost Guessable
Easy to read, understand, remember
jQuery API
Richard D. Worth
jQuery’s Focus
DOM Manip.
Ajax
Events
Animation
Richard D. Worth
.next() .prev()
.find() .children()
.parent() .parents()
.filter()
DOM Traversing
Richard D. Worth
.text() .html()
.attr() .removeAttr()
.remove() // returns element
.css()
Attributes
Richard D. Worth
.css(key, value)
.css({key: value, key: value})
.addClass() .removeClass()
.toggleClass()
CSS / Styles
Richard D. Worth
.append() .prepend()
.before() .after()
.insertBefore() .insertAfter()
$("<div>New Element</div>")
DOM Construction
Richard D. Worth
Overloaded
Richard D. Worth
$(selector)
$(HTML)
$(DOMElement)
$(function) // DOM Ready
$(selector, context)
Optional Context
Richard D. Worth
.click(fn) .click()
.toggle(fn, fn) .toggle()
.click(fn) -> .bind("click", fn)
.click() -> .trigger("click")
Events
Richard D. Worth
Event Handler/Callback
Callback gets context (this)
‘this’ is always a DOMElement
First parameter is Event object
Richard D. Worth
.load(url)
.load(url + " " + selector)
Ajax
Richard D. Worth
$.get()
$.post()
$.getJSON()
$.getScript()
Ajax
Richard D. Worth
$.ajaxSend()
$.ajaxStart() $.ajaxStop()
$.ajaxError() $.ajaxSuccess()
$.ajaxComplete()
Ajax Events
Richard D. Worth
.show() .hide() .toggle()
.fadeIn() .fadeOut() .fadeTo()
.animate() .stop() .queue()
.slideUp() .slideDown() .slideToggle()
Animations
Richard D. Worth
Richard D. Worth
Plugins Keep
The Core Lean
Richard D. Worth
Writing a jQuery
Plugin
Richard D. Worth
Extending the
Selector Engine
Richard D. Worth
Custom Events
Richard D. Worth
.data()
Richard D. Worth
Q&A
Books
Richard D. Worth
Learning jQuery (Packt)
jQuery in Action (Manning)
Karl Swedberg, Jonathan Chaffer
Bear Bibeault, Yehuda Katz

More Related Content

What's hot

Android application penetration testing
Android application penetration testingAndroid application penetration testing
Android application penetration testingRoshan Kumar Gami
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapKaty Slemon
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Languageguestceb98b
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IOChristian Joudrey
 
Using Xcore with Xtext
Using Xcore with XtextUsing Xcore with Xtext
Using Xcore with XtextHolger Schill
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js선협 이
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우Arawn Park
 
Firebase Auth Tutorial
Firebase Auth TutorialFirebase Auth Tutorial
Firebase Auth TutorialBukhori Aqid
 
Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Alex Borysov
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Mobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMartinSotirov
 
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式Shengyou Fan
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 

What's hot (20)

Android application penetration testing
Android application penetration testingAndroid application penetration testing
Android application penetration testing
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Using Xcore with Xtext
Using Xcore with XtextUsing Xcore with Xtext
Using Xcore with Xtext
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
File system node js
File system node jsFile system node js
File system node js
 
코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우
 
Express node js
Express node jsExpress node js
Express node js
 
Firebase Auth Tutorial
Firebase Auth TutorialFirebase Auth Tutorial
Firebase Auth Tutorial
 
Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Hands on the Gradle
Hands on the GradleHands on the Gradle
Hands on the Gradle
 
Mobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to Native
 
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 

Viewers also liked

SydPHP Security in PHP
SydPHP Security in PHPSydPHP Security in PHP
SydPHP Security in PHPAllan Shone
 
RedHat-System Administration I - RH124
RedHat-System Administration I - RH124RedHat-System Administration I - RH124
RedHat-System Administration I - RH124Nikola Tokić
 
Php Security Workshop
Php Security WorkshopPhp Security Workshop
Php Security WorkshopAung Khant
 
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Chris Tankersley
 
Web Technology – Web Server Setup : Chris Uriarte
Web Technology – Web Server Setup : Chris UriarteWeb Technology – Web Server Setup : Chris Uriarte
Web Technology – Web Server Setup : Chris Uriartewebhostingguy
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And AnishOSSCube
 
Effective communication
Effective communicationEffective communication
Effective communicationhussulinux
 
Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnoldus Inc.
 
Quick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantQuick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantJoe Ferguson
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsJoe Ferguson
 
HTML validation, microformats, jQuery
HTML validation, microformats, jQueryHTML validation, microformats, jQuery
HTML validation, microformats, jQueryJeffrey Barke
 
Red Hat Training México /// Calendario de cursos 2016
Red Hat Training México /// Calendario de cursos 2016Red Hat Training México /// Calendario de cursos 2016
Red Hat Training México /// Calendario de cursos 2016Red Hat
 
jQuery Plugins Intro
jQuery Plugins IntrojQuery Plugins Intro
jQuery Plugins IntroCasey West
 
Scalable Internet Servers and Load Balancing
Scalable Internet Servers and Load BalancingScalable Internet Servers and Load Balancing
Scalable Internet Servers and Load BalancingInformation Technology
 
Safety LAMP: data security & agile languages
Safety LAMP: data security & agile languagesSafety LAMP: data security & agile languages
Safety LAMP: data security & agile languagesPostgreSQL Experts, Inc.
 
ClueCon2009: The Security Saga of SysAdmin Steve
ClueCon2009: The Security Saga of SysAdmin SteveClueCon2009: The Security Saga of SysAdmin Steve
ClueCon2009: The Security Saga of SysAdmin SteveDan York
 
CSS3 and jQuery
CSS3 and jQueryCSS3 and jQuery
CSS3 and jQuerypsophy
 

Viewers also liked (20)

SydPHP Security in PHP
SydPHP Security in PHPSydPHP Security in PHP
SydPHP Security in PHP
 
RedHat-System Administration I - RH124
RedHat-System Administration I - RH124RedHat-System Administration I - RH124
RedHat-System Administration I - RH124
 
Php Security Workshop
Php Security WorkshopPhp Security Workshop
Php Security Workshop
 
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
 
Web Technology – Web Server Setup : Chris Uriarte
Web Technology – Web Server Setup : Chris UriarteWeb Technology – Web Server Setup : Chris Uriarte
Web Technology – Web Server Setup : Chris Uriarte
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
Effective communication
Effective communicationEffective communication
Effective communication
 
jQuery
jQueryjQuery
jQuery
 
Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slides
 
Quick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantQuick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with Vagrant
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basics
 
HTML validation, microformats, jQuery
HTML validation, microformats, jQueryHTML validation, microformats, jQuery
HTML validation, microformats, jQuery
 
Red Hat Training México /// Calendario de cursos 2016
Red Hat Training México /// Calendario de cursos 2016Red Hat Training México /// Calendario de cursos 2016
Red Hat Training México /// Calendario de cursos 2016
 
jQuery Plugins Intro
jQuery Plugins IntrojQuery Plugins Intro
jQuery Plugins Intro
 
Scalable Internet Servers and Load Balancing
Scalable Internet Servers and Load BalancingScalable Internet Servers and Load Balancing
Scalable Internet Servers and Load Balancing
 
Safety LAMP: data security & agile languages
Safety LAMP: data security & agile languagesSafety LAMP: data security & agile languages
Safety LAMP: data security & agile languages
 
ClueCon2009: The Security Saga of SysAdmin Steve
ClueCon2009: The Security Saga of SysAdmin SteveClueCon2009: The Security Saga of SysAdmin Steve
ClueCon2009: The Security Saga of SysAdmin Steve
 
PHP
PHPPHP
PHP
 
RHCSA
RHCSARHCSA
RHCSA
 
CSS3 and jQuery
CSS3 and jQueryCSS3 and jQuery
CSS3 and jQuery
 

jQuery Stack Overflow DevDays DC 2009