SlideShare uma empresa Scribd logo
1 de 25
Confidential
Introduction to jQuery
Hunter Wu
Nov. 30, 2007
Confidential
Table of Contents
• About jQuery
• Finding Elements
• Performing Actions
• A Concept of Using jQuery
• Appendix
About jQuery
Confidential
jQuery
• Released on Jan. 2006
• Focus on DOM Traversal
• Built in support for Events, Ajax, and Animations
• Succinct code, small file size
• Extensible via a plugin architecture
• Dual licensed under the MIT and GPL licenses
Find something
Perform actions
against on it
Confidential
Trends
• 2007 Ajaxian.com Reader Survey Results
Survey Result of 2006
Finding Elements
Confidential
Traditional Ways
document.getElementById('txt1')
document.getElementsByTagName('input')
document.forms['form1'].elements['txt1']
document.images['img1']
document.form1.txt1
document.form1.img1
document.img1
form1.txt1
document.all.txt1
document.all['txt1']
document.layers['div1']
window.form1
document.forms['form1'].elements['img1']
Confidential
Comparison
Native Function jQuery
Get an
element
var txt1 = document.
getElementById("txt1");
var txt1 = $("#txt1");
Return [Element] [jQuery Object]
Get value var t2 = txt1.value; var t2 = txt1.val();
Set value txt1.value = "hello"; txt1.val("hello");
Confidential
CSS Selectors
CSS Selectors Effected Element(s) jQuery Syntax
#mainTb {…} id="mainTb" $("#mainTb")
 matches a single element with the given id
.bk13 {…} class="bk13" $(".bk13")
 matches all elements with the given class
input {…} <input …> $("input")
 matches all elements with the given tag
Confidential
More Selector Examples
$("#orderedlist > li")
(Hierarchy) Selects all child lis of the element with the
id orderedlist.
$("#orderedlist li:last")
(Basic Filters) Selects the last child li of the element
with the id orderedlist.
Confidential
More Selector Examples
$("#orderedlist > li")
(Hierarchy) Selects all child lis of the element with the
id orderedlist.
$("#orderedlist li:last")
(Basic Filters) Selects the last child li of the element
with the id orderedlist.
$("img[src*=yimg.com]")
Confidential
More Selector Examples
$("#orderedlist > li")
(Hierarchy) Selects all child lis of the element with the
id orderedlist.
$("#orderedlist li:last")
(Basic Filters) Selects the last child li of the element
with the id orderedlist.
$("img[src*=yimg.com]")
(Attribute Filters) Selects all image elements that have
the src attribute and it contants a certain value.
Full documentation of selectors:
http://docs.jquery.com/Selectors
Peforming Actions
Confidential
Basic Effects
$("img[src*=yimg.com]").hide();
 Hides each of the matched elements if they are shown.
$("img[src*=yimg.com]").fadeOut();       //fade out
$("img[src*=yimg.com]").fadeIn();        //fade in
$("img[src*=yimg.com]").fadeOut();
$("img[src*=yimg.com]").fadeIn();
$("img[src*=yimg.com]").fadeOut('slow'); //fade out slowly
 Apply fade-out/fade-in several times to each of the
matched elements.
Confidential
Chainability (The Magic of jQuery)
• Chainable Functions:
$("img[src*=yimg.com]").fadeOut().fadeIn().fadeOut().
fadeIn().fadeOut('slow');
• Another Example:
$("img[src*=yimg.com]").
attr("src", "http://www.ruten.com.tw/img/userbanner.gif").
attr("border", "0").
removeAttr("height").
removeAttr("width").
wrap("<a href="" +
$("a[href*=/user/index.php?sid=]:first").attr("href") +
""></a>");
A Concept of Using jQuery
Confidential
Ruten UI Toolbox
• Users are not familiar with Image Processing
• Providing online, easy-to-use APIs for them
• Effects may look like:
Confidential
Ruten UI Toolbox (cont.)
• For Users
• Add filter names to the class attribute, and it’s set.
<img src="..." class="glossy reflex">
• For Developers
• One line to rule them all.
/* a pseudo code */
$("img[class*=corner]").addEffect("corner").
end().find("img[class*=edges]").addEffect("edges").
end().find("img[class*=filmed]").addEffect("filmed").
end().find("img[class*=glossy]").addEffect("glossy").
end().find("img[class*=reflex]").addEffect("reflex");
Appendix
Confidential
The Author of jQuery
• John Resig
• Work for Mozilla Corp.
• The author of the book "Pro JavaScript Techniques"
• The speaker of "Building a JavaScript Library" on Google
Tech Talk
作者: Resig, John
出版社: Apress
初版日: 2006-12-11
商品條碼: 9781590597279
ISBN 條碼
:
1590597273
資料提供:
Confidential
Using jQuery with Other Libraries
• Loading the other library before jQuery
<script src="prototype.js"></script>
<script src="jquery.js"></script>
• Overriding the $-function
jQuery.noConflict();
var theTable = jQuery("#mainTb");
• Using another shortcut for jQuery
var $j = jQuery.noConflict();
var theTable = $j("#mainTb");
Any Questions?
以下是備而不用
Confidential
More Features of jQuery
• Namespacing (only one global variable: jQuery)
• Implementations of Object-Orented Design
• Unobtrusive scripting
Confidential
Launching Code on Document Ready
• Limitations of window.onload
• Can not be used twice in one page
• The Javascript code isn't run until all images are finished
downloading
• Solution from jQuery
$(document).ready(function(){
// Your code here
});

Mais conteúdo relacionado

Mais procurados

Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Andrii Lundiak
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j querythewarlog
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
jQuery Framework - Property Content
jQuery Framework - Property ContentjQuery Framework - Property Content
jQuery Framework - Property Contentjagadeeshm
 
Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25Robert Szaloki
 
Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25EU Edge
 
Marionette: the Backbone framework
Marionette: the Backbone frameworkMarionette: the Backbone framework
Marionette: the Backbone frameworkfrontendne
 
jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit Girish Venkatachalam
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slidesMasterCode.vn
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIScott Gardner
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsEPAM Systems
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 

Mais procurados (20)

Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
jQuery Framework - Property Content
jQuery Framework - Property ContentjQuery Framework - Property Content
jQuery Framework - Property Content
 
Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25
 
Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25
 
jQuery
jQueryjQuery
jQuery
 
Marionette: the Backbone framework
Marionette: the Backbone frameworkMarionette: the Backbone framework
Marionette: the Backbone framework
 
jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit jQuery - write less, do more javascript toolkit
jQuery - write less, do more javascript toolkit
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery
jQueryjQuery
jQuery
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slides
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUI
 
Jquery
JqueryJquery
Jquery
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 

Semelhante a Introduction.to.j query (20)

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 besic
jQuery besicjQuery besic
jQuery besic
 
Jquery
JqueryJquery
Jquery
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
JQuery
JQueryJQuery
JQuery
 
Jquery introduce
Jquery introduceJquery introduce
Jquery introduce
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
J query
J queryJ query
J query
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Jquery
JqueryJquery
Jquery
 
Jquery library
Jquery libraryJquery library
Jquery library
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 

Introduction.to.j query