SlideShare uma empresa Scribd logo
1 de 29
JQUERY FOR
BEGINNERS
WHO AM I?
www.jackfranklin.co.uk

   @Jack_Franklin
jQuery
jQuery is a fast and concise JavaScript Library that
simplifies HTML document traversing, event
handling, animating, and Ajax interactions for rapid
web development. jQuery is designed to change
the way that you write JavaScript.
WHY JQUERY?
1. Cross Browser (IE6+ OMG)
   2. Superb Documentation
       3. Widely adopted
        4. Lightweight.
jQuery writes itself
$(“#aside”).fadeOut().css(“width”,
“300px”).addClass(“jquery-rocks”).fadeIn();
jQuery writes itself
$(“#aside”) //#aside
.fadeOut() //fade it out
.css(“width”, “300px”) //set width
.addClass(“jquery-rocks”) //add class
.fadeIn(); //fade in
If you know CSS...
$(“#aside”) // id of aside
$(“.heading”) // class of heading
$(“div”) // every div
$(“a#anchor”) // a with id of anchor
$(“p a”) //a inside p
$(“div>h1”) //h1 direct child of div
Support for CSS3...
$(“p:nth-child(2)”);
$(“p:even”);
$(“p:not(.intro)”);




             ...even in IE6+
Events
$(“someElement”).event(function() {
    /*something happens!*/
});
Events: Click
$(“a”).click(function(e) {
    e.preventDefault();
    console.log(“Link clicked!”);
});
Events: Click
$(“a”).click(function(e) {
    console.log(“Link clicked!”);
    return false;
});
Events: Click
$(“a”).click(function(e) {
    e.preventDefault();
    e.stopPropagation();
    console.log(“Link clicked!”);
});
Events: Hover
$(“h1”).hover(
   function() {
      console.log(“hovered on”);
   },
   function() {
      console.log(“hovered off”);
   }
);
Events: Delegate
$(“ul”).delegate(“li”, “click”, function() {
    console.log(“li clicked”);
});
When you’re ready...
$(document).ready(function() {
    /*all your code here*/
});
//same thing:
$(function() {
    /*all your code here*/
});
Including jQuery
Google CDN: http://code.google.com/apis/
libraries/devguide.html#jquery

Local jQuery.
Better safe than sorry
<script src="//ajax.googleapis.com/ajax/libs/
jquery/1.6.4/jquery.min.js"></script>
<script>window.jQuery ||
document.write('<script src="js/libs/
jquery-1.6.4.min.js"></script>')</script>
Getting animated
$(“p”).fadeOut();
$(“div”).slideUp();
$(“div”).slideToggle();
$(“p”).animate({
   ‘margin-left’ : ‘+=20px’,
   ‘opacity’ : 0.5
}, 500);
Callbacks
$(“p”).animate({
    ‘margin-left’ : ‘+=20px’,
    ‘opacity’ : 0.5
}, 500, function() {
    console.log(“animations done!”);
});
jQuery & CSS
$(“p”).css(“width”, “200px”);
$(“p”).css({
    “width” : “200px”,
    “opacity” : 0.9,
    “height” : “400px”
});
Add CSS in CSS!
.newCss {
   width: 200px;
   opacity: 0.9;
   height: 400px;
}
$(“p”).addClass(“newCss”);
Creation
$(“<img />”, {
    “alt” : “my alternative text”,
    click : function() {
       console.log(“clicked”);
    }
});
Manipulation
$(“img”)
.prependTo(“#gallery”)
.wrap(“<a/>”);

$(“#aside”).clone().attr(“id”, “new-
aside”).appendTo(“body”);
Traversing the DOM
//useful ones:
$(elem).next() //next sibling
$(elem).parent() //parent
$(elem).nextAll() //all next siblings
$(elem).children(“img”) //direct img children
$(elem).find(“img”) //img inside elem
Looping the Set
$(“li”).each(function(i, item) {
    $(item).attr(“id”, “link” + i);
});
Better... (less work)
$(“li”).each(function(i, item) {
    item.id = “link” + i;
});
jQuery and AJAX
$.ajax({
    ‘url’ : ‘http://somejson.com/api’,
    ‘method’ : ‘get’,
    ‘dataType’ : ‘json’,
    success: function(d) {
       console.log(d);
    }
});
Resources
irc.freenode.net #jquery
docs.jquery.com
jqueryfordesigners.com
paulirish.com
THANKS FOR
LISTENING...QUESTIONS?
    (slides online soon)

@JACK_FRANKLIN

Mais conteúdo relacionado

Mais procurados

Auto tools
Auto toolsAuto tools
Auto tools
祺 周
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
Gonzalo Parra
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
Erik Duval
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjs
ji guang
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j query
Baoyu Xu
 

Mais procurados (20)

Auto tools
Auto toolsAuto tools
Auto tools
 
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
Yuihacku iitd-sumana
Yuihacku iitd-sumanaYuihacku iitd-sumana
Yuihacku iitd-sumana
 
php Slideshare
php Slidesharephp Slideshare
php Slideshare
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjs
 
Intro to jquery
Intro to jqueryIntro to jquery
Intro to jquery
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
An Introduction to WordPress Hooks
An Introduction to WordPress HooksAn Introduction to WordPress Hooks
An Introduction to WordPress Hooks
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Canjs
CanjsCanjs
Canjs
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j query
 
One Size Fits All
One Size Fits AllOne Size Fits All
One Size Fits All
 

Destaque (7)

CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
Designing for the Teenage Market
Designing for the Teenage MarketDesigning for the Teenage Market
Designing for the Teenage Market
 
jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Semelhante a Introduction to jQuery - Barcamp London 9

Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
Chris Coyier
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Angel Ruiz
 

Semelhante a Introduction to jQuery - Barcamp London 9 (20)

Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 
J query training
J query trainingJ query training
J query training
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery
jQueryjQuery
jQuery
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to Jquery
 
Jquery
JqueryJquery
Jquery
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
jQuery Foot-Gun Features
jQuery Foot-Gun FeaturesjQuery Foot-Gun Features
jQuery Foot-Gun Features
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Javascript in Plone
Javascript in PloneJavascript in Plone
Javascript in Plone
 
KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Introduction to jQuery - Barcamp London 9

Notas do Editor

  1. interrupt me with questions whenever!\n
  2. student &amp; developer\n
  3. \n
  4. student &amp; developer\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. this stops the link &amp;#x201C;working&amp;#x201D; but not event bubbling\n
  11. this stops bubbling &amp; the link acting like it should\n
  12. same effect as return false now\n
  13. \n
  14. Delegate is awesome when you need to bind a link to a large group\n
  15. include your script right before the end body, don&amp;#x2019;t need to do this.\n
  16. Google = caching = win\n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. find = any level\nchildren = first level (direct descendants)\n
  25. find = any level\nchildren = first level (direct descendants)\n
  26. don&amp;#x2019;t use jQuery if you don&amp;#x2019;t have to!\n
  27. don&amp;#x2019;t use jQuery if you don&amp;#x2019;t have to!\n
  28. don&amp;#x2019;t use jQuery if you don&amp;#x2019;t have to!\n
  29. \n