SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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 的昨天、今天与明天
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Introduction to jQuery - Barcamp London 9

Hinweis der Redaktion

  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