SlideShare a Scribd company logo
jQuery Conference San Francisco Bay Area 2010




                          jQuery('#knowledge')
                            .appendTo('#you');
                                      Mike Hostetler
                                     @mikehostetler
                                http://mike-hostetler.com

   Copyright © 2010 appendTo, LLC.
                                                            THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                           The jQuery Project




   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                         jQuery Project - jquery.org
                                      (Software Freedom Conservancy)


                                     jQuery Core          jQuery UI

                                     jquery.com         jqueryUI.com




                                       Sizzle JS            QUnit

                                     sizzlejs.com         qunitjs.com



   Copyright © 2010 appendTo, LLC.
                                                                        THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                        Using jQuery
 ‣ jquery.com        Downloading


 ‣ api.jquery.com          Documentation


 ‣ forum.jquery.com            Community


 ‣ meetups.jquery.com                Local   Community


 ‣ plugins.jquery.com            Extending


 ‣ jqueryui.com         Project Supported UI Library




   Copyright © 2010 appendTo, LLC.
                                                         THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                 Including jQuery




   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Including jQuery
 ‣ Download        jQuery.com


 ‣ Locations

    ‣ Self hosted       Download and include in your project


    ‣ CDN     Google, Microsoft, jQuery


 ‣ Forms

    ‣ Source vs. Minified




   Copyright © 2010 appendTo, LLC.
                                                               THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010



                                                Source




                       Minified
   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                              Finding Something




   Copyright © 2010 appendTo, LLC.
                                                  THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Finding Something
   // Select By ID

   <div id=”foo”></div>
   <div></div>

   $(‘#foo’);

   <div id=”foo”></div>
   <div></div>




   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Finding Something
   // Select by class

   <div class=”myClass foo bar”></div>
   <div class=”baz myClass”></div>
   <div class=”bar”></div>

   $(‘.myClass’)

   <div class=”myClass foo bar”></div>
   <div class=”baz myClass”></div>
   <div class=”bar”></div>



   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Finding Something
   // Select by tag
   <ul>
   <li>Apple</li>
   <li>Pear</li>
   </ul>

   $(“li”);

   <ul>
   <li>Apple</li>
   <li>Pear</li>
   </ul>

   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




             Finding Something in Context
 ‣ Entire Document
   $(‘div’)

 ‣ Scope your selector
   $(‘selector’, <context>)
   $(‘#table’).find(‘selector’)

 ‣ $(‘a’).click(function() {
         $(‘span’, this)...
   });




   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                         Demo!




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Do Something




   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Do Something
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   // Find Something
   $(‘p’)
   // Do Something
   $(‘p’).hide();

   // Generic Syntax
   $(‘p’) . <Method Name> ( [PARAMETERS] );


   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                            Showing and Hiding
   // HTML
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   // Show the elements
   $(‘p’).show();

   // Hide the elements
   $(‘p’).hide();



   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                            Showing and Hiding
   // HTML
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   // Show the elements
   $(‘p’).show();

   // Hide the elements
   $(‘p’).hide();



   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                       Iteration
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   $(‘p’).each(function() {
    // Operates on each p individually
    var rand;
    rand = Math.floor( Math.random() * 1 );
    if(rand > 1) {
      $(this).hide();
    }
   });

   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                       Iteration
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   $(‘p’).each(function() {
    // Operates on each p individually
    var rand;
    rand = Math.floor( Math.random() * 1 );
    if(rand > 1) {
      $(this).hide();
    }
   });

   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                       Iteration
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   $(‘p’).each(function() {
    // Operates on each p individually
    var rand;
    rand = Math.floor( Math.random() * 1 );
    if(rand > 1) {
      $(this).hide();
    }
   });

   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                          Styling
   // HTML
   <p>One</p>
   <p class=”foo”>Two</p>
   <p>Three</p>

   $(‘p’).addClass(‘enabled’);

   $(‘p’).removeClass(‘foo’);

   $(‘p’).toggleClass(‘foo’);



   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                          Styling
   // HTML
   <p class=”enabled”>One</p>
   <p class=”enabled foo”>Two</p>
   <p class=”enabled”>Three</p>

   $(‘p’).addClass(‘enabled’);

   $(‘p’).removeClass(‘foo’);

   $(‘p’).toggleClass(‘foo’);



   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                          Styling
   // HTML
   <p class=”enabled”>One</p>
   <p class=”enabled”>Two</p>
   <p class=”enabled”>Three</p>

   $(‘p’).addClass(‘enabled’);

   $(‘p’).removeClass(‘foo’);

   $(‘p’).toggleClass(‘foo’);



   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                          Styling
   // HTML
   <p class=”enabled foo”>One</p>
   <p class=”enabled foo”>Two</p>
   <p class=”enabled foo”>Three</p>

   $(‘p’).addClass(‘enabled’);

   $(‘p’).removeClass(‘foo’);

   $(‘p’).toggleClass(‘foo’);



   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Method Chaining




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Method Chaining
   $(‘tr:odd’).addClass(‘odd’)
    .find(‘td.company’)
    .addClass(‘companyName’);

   $(‘tr:odd’).addClass(‘odd’)
    .find(‘td.company’)
      .addClass(‘companyName’)
    .end();




   Copyright © 2010 appendTo, LLC.
                                                       THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Method Chaining
   $(‘tr’)
    .filter(‘:odd’)
      .addClass(‘odd’)
    .end()
    .find(‘td.company’)
      .addClass(‘companyName’);




   Copyright © 2010 appendTo, LLC.
                                                       THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                           DOM Manipulation




   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                Creating Elements
   // New in 1.4
   $("<div/>", {
    class: "test",
    text: "Click me!",
    click: function(){
      $(this).toggleClass("test");
    }
   });

   // Clicking toggles the class
   <div class=”test”>Click me!</div>


   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Inserting Elements
   // Before
   <p>Apple</p>
   <p>Orange</p>

   $(‘p’).after(‘<img src=”logo.png” />’);

   // After
   <p>Apple</p>
   <img src=”logo.png />
   <p>Orange</p>
   <img src=”logo.png />


   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               Inserting Elements
   // Before
   <p id=”apple”>Apple</p>
   <p id=”orange”>Orange</p>

   $(‘<img src=”apple.png” />’).prependTo(‘#apple’);
   $(‘<img src=”orange.png” />’).appendTo(‘#orange’);

   // After
   <p id=”apple”><img src=”apple.png” />Apple</p>
   <p id=”orange”>Orange<img src=”orange.png” /></p>



   Copyright © 2010 appendTo, LLC.
                                                        THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                             Removing Elements
   // Before
   <div>
    <p>Red</p>
    <p>Green</p>
   </div>

   // Removing Elements Directly
   $(‘p’).remove();

   // After
   <div>
   </div>

   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                              Wrapping Elements
   // Before
   <p>Hello world</p>
   <p>Foo bar</p>

   $(‘p’).wrap(‘<div></div>’);


   // After
   <div><p>Hello world</p></div>
   <div><p>Foo bar</p></div>




   Copyright © 2010 appendTo, LLC.
                                                  THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




              Unwrapping Elements               (new in 1.4+)


   // Before
   <div><p>Hello world</p></div>
   <div><p>Foo bar</p></div>

   //Individually
   $(‘p’).unwrap();

   // After
   <p>Hello world</p>
   <p>Foo bar</p>




   Copyright © 2010 appendTo, LLC.
                                                          THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Binding Events




   Copyright © 2010 appendTo, LLC.
                                                      THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Click Event
   // HTML
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   $(‘p’).click(function(event) {
    $(this).css(‘color’, ‘red’);
   });




   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Click Event
   // HTML
   <p>One</p>
   <p style=”color: red”>Two</p> // Clicked!
   <p>Three</p>

   $(‘p’).click(function(event) {
    $(this).css(‘color’, ‘red’);
   });




   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                             Hover Pseudo Event
   // HTML
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   $(‘p’).hover(function(event) {
    $(this).css(‘color’, ‘red’);
   }, function() {
    $(this).css(‘color’, ‘’);
   });




   Copyright © 2010 appendTo, LLC.
                                                  THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                           Binding & Unbinding
   // HTML
   <p>One</p>
   <p>Two</p>
   <p>Three</p>

   // Add event
   $(‘p’).bind(‘click’,function(event) {
    $(this).css(‘color’, ‘red’);
   });

   // Remove event
   $(‘p’).unbind(‘click’);

   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                 Binding Events with .bind()
   // Binding an event

   $('a.tab').bind('click',function(e){
    // event handling code
    $(this).css(‘color’, ‘red’);
   });

   // Unbinding an event 

   $('a.tab').unbind('click');



   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Binding Events
   // Bind an event to execute once

   $('a.tab').one('click',function(e){
     // event handling code
     $(this).css(‘color’,‘red’);
   });




   Copyright © 2010 appendTo, LLC.
                                                      THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                         Demo!




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                                Ajax




   Copyright © 2010 appendTo, LLC.
                                                       THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                Making a Request
   $.get(‘page.php’, function(data) {
      $(data).appendTo(‘body’);
   }, ‘html’);

   var data = { fname: ‘Jonathan’ };
   $.post(‘page.php’, data, function(data) {
      $(data).appendTo(‘body’);
   }, ‘html’);




   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                       Making a Request JSON
   // Response
   {“names”: [“Jonathan”, “Mike”, “Rob”],
    “states”: {“NE” : “Nebraska”},
    “year” : “2010” }


   $.getJSON(‘page.php’, function(json) {
     $(‘body’).append( json.names[0] );
     $(‘body’).append( json.states.NE );
   });



   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                       Making a Request JSON
   // Response
   { “names”: [“Jonathan”, “Mike”, “Rob”] }


   $.getJSON(‘page.php’, function(json) {
     $.each(json.names, function(i, val) {
       $(‘body’).append( val );
     });
   });




   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                   Writing Your First Plugin




   Copyright © 2010 appendTo, LLC.
                                                THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                      Writing your first Plugin
   $.fn.elementCount = function() {
     alert(‘Element count: ’ + this.length);
   };


   $(‘p’).elementCount();




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                           Plugins and Iteration
   $.fn.elementCount = function() {
     // this is a jQuery Object
     this.each(function(i) {
       $(this).html($(this).html() +‘ ‘+ i);
     });
   };


   $(‘p’).elementCount();




   Copyright © 2010 appendTo, LLC.
                                                   THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                          Plugins and Chaining
   $.fn.elementCount = function() {
     // this is a jQuery Object
     return this.each(function(i) {
       $(this).html($(this).html() +‘ ‘+ i);
     });
   };


   $(‘p’).elementCount().addClass(‘active’);;




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                          Plugins and Chaining
   // Plugin is required to return this
   $.fn.stPatricks = function() {
     return this.css(‘color’, ‘green’);
   };


   $(‘p’).stPatricks().addClass(‘active’);




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                             The Plugin Pattern




   Copyright © 2010 appendTo, LLC.
                                                  THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               The Plugin Pattern
   (function($) {
    $.fn.elementCount = function() {
     return this.each(function(i) {
       $(this).html($(this).html() +‘ ‘+ i);
     });
    };
   })(jQuery);

   $(‘p’).elementCount();




   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               The Plugin Pattern
   (function($) {
    $.fn.elementCount = function(options) {
     return this.each(function(i) {
       var j = i + options.start;
       $(this).html($(this).html() +‘ ‘+ j);
     });
    };
   })(jQuery);

   $(‘p’).elementCount({start: 10});



   Copyright © 2010 appendTo, LLC.
                                                    THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                               The Plugin Pattern
   (function($) {
    $.fn.elementCount = function(options) {
     var j; if ( $.isFunction(options.begin) ) { options.begin(); }
     return this.each(function(i) {
       j = i + options.start;
       $(this).html($(this).html() +‘ ‘+ j);
     });
    };
   })(jQuery);
   $(‘p’).elementCount( start: 10,
     begin: function() {alert(‘BEGIN!’)}
   });

   Copyright © 2010 appendTo, LLC.
                                                              THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                         Demo!




   Copyright © 2010 appendTo, LLC.
                                                 THE jOUERY COMPANY
jQuery Conference San Francisco Bay Area 2010




                                     Thank You!
                                      Mike Hostetler
                                     @mikehostetler
                                http://mike-hostetler.com


   Copyright © 2010 appendTo, LLC.
                                                            THE jOUERY COMPANY

More Related Content

What's hot (20)

PDF
jQuery Essentials
Bedis ElAchèche
 
PDF
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PDF
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
PDF
JavaScript Libraries (Kings of Code)
jeresig
 
PDF
JavaScript Libraries (@Media)
jeresig
 
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
PDF
jQuery for beginners
Siva Arunachalam
 
PPTX
A Rich Web experience with jQuery, Ajax and .NET
James Johnson
 
PPT
Jquery ui
adm_exoplatform
 
PPTX
SharePoint and jQuery Essentials
Mark Rackley
 
PDF
OOCSS for JavaScript Pirates jQcon Boston
John Hann
 
PDF
jQuery Introduction
Arwid Bancewicz
 
KEY
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
 
KEY
User Interface Development with jQuery
colinbdclark
 
PPTX
jQuery
Dileep Mishra
 
PDF
jQuery (DrupalCamp Toronto)
jeresig
 
PDF
jQuery (BostonPHP)
jeresig
 
PDF
jQuery (MeshU)
jeresig
 
PPTX
jQuery Presentation
Rod Johnson
 
jQuery Essentials
Bedis ElAchèche
 
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
JavaScript Libraries (Kings of Code)
jeresig
 
JavaScript Libraries (@Media)
jeresig
 
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
jQuery for beginners
Siva Arunachalam
 
A Rich Web experience with jQuery, Ajax and .NET
James Johnson
 
Jquery ui
adm_exoplatform
 
SharePoint and jQuery Essentials
Mark Rackley
 
OOCSS for JavaScript Pirates jQcon Boston
John Hann
 
jQuery Introduction
Arwid Bancewicz
 
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
 
User Interface Development with jQuery
colinbdclark
 
jQuery (DrupalCamp Toronto)
jeresig
 
jQuery (BostonPHP)
jeresig
 
jQuery (MeshU)
jeresig
 
jQuery Presentation
Rod Johnson
 

Similar to jQuery('#knowledge').appendTo('#you'); (20)

PDF
Cooking with jQuery
mikehostetler
 
PDF
Cooking with jQuery @ OSCON 2010
appendTo
 
PDF
What's this jQuery? Where it came from, and how it will drive innovation
Marakana Inc.
 
PDF
Idiots guide to jquery
Mark Casias
 
PPTX
Introduction to jQuery
Alek Davis
 
PPTX
Web technologies-course 11.pptx
Stefan Oprea
 
PPT
Introduction to jQuery
Andres Baravalle
 
PPTX
jQuery Presentasion
Mohammad Usman
 
PDF
fuser interface-development-using-jquery
Kostas Mavridis
 
PDF
Introduction to jQuery :: CharlotteJS
gjj391
 
ODP
Jquery- One slide completing all JQuery
Knoldus Inc.
 
PDF
J query fundamentals
Attaporn Ninsuwan
 
PDF
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PPT
JQuery introduction
NexThoughts Technologies
 
PDF
Devdays Seattle jQuery Intro for Developers
cody lindley
 
PDF
jQuery Rescue Adventure
Allegient
 
PPT
jQuery Introduction/ jquery basic concept
MuhammadJameel83
 
PPTX
Jquery fundamentals
Salvatore Fazio
 
PDF
Adv WTAdvanced Web Tech_unit 2_Adv WT.pdf
GauravDwivedi695361
 
Cooking with jQuery
mikehostetler
 
Cooking with jQuery @ OSCON 2010
appendTo
 
What's this jQuery? Where it came from, and how it will drive innovation
Marakana Inc.
 
Idiots guide to jquery
Mark Casias
 
Introduction to jQuery
Alek Davis
 
Web technologies-course 11.pptx
Stefan Oprea
 
Introduction to jQuery
Andres Baravalle
 
jQuery Presentasion
Mohammad Usman
 
fuser interface-development-using-jquery
Kostas Mavridis
 
Introduction to jQuery :: CharlotteJS
gjj391
 
Jquery- One slide completing all JQuery
Knoldus Inc.
 
J query fundamentals
Attaporn Ninsuwan
 
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
Week 4 - jQuery + Ajax
baygross
 
JQuery introduction
NexThoughts Technologies
 
Devdays Seattle jQuery Intro for Developers
cody lindley
 
jQuery Rescue Adventure
Allegient
 
jQuery Introduction/ jquery basic concept
MuhammadJameel83
 
Jquery fundamentals
Salvatore Fazio
 
Adv WTAdvanced Web Tech_unit 2_Adv WT.pdf
GauravDwivedi695361
 
Ad

Recently uploaded (20)

PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
Sustainable and comertially viable mining process.pdf
Avijit Kumar Roy
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Top Managed Service Providers in Los Angeles
Captain IT
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Ad

jQuery('#knowledge').appendTo('#you');

  • 1. jQuery Conference San Francisco Bay Area 2010 jQuery('#knowledge') .appendTo('#you'); Mike Hostetler @mikehostetler http://mike-hostetler.com Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 2. jQuery Conference San Francisco Bay Area 2010 The jQuery Project Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 3. jQuery Conference San Francisco Bay Area 2010 jQuery Project - jquery.org (Software Freedom Conservancy) jQuery Core jQuery UI jquery.com jqueryUI.com Sizzle JS QUnit sizzlejs.com qunitjs.com Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 4. jQuery Conference San Francisco Bay Area 2010 Using jQuery ‣ jquery.com Downloading ‣ api.jquery.com Documentation ‣ forum.jquery.com Community ‣ meetups.jquery.com Local Community ‣ plugins.jquery.com Extending ‣ jqueryui.com Project Supported UI Library Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 5. jQuery Conference San Francisco Bay Area 2010 Including jQuery Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 6. jQuery Conference San Francisco Bay Area 2010 Including jQuery ‣ Download jQuery.com ‣ Locations ‣ Self hosted Download and include in your project ‣ CDN Google, Microsoft, jQuery ‣ Forms ‣ Source vs. Minified Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 7. jQuery Conference San Francisco Bay Area 2010 Source Minified Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 8. jQuery Conference San Francisco Bay Area 2010 Finding Something Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 9. jQuery Conference San Francisco Bay Area 2010 Finding Something // Select By ID <div id=”foo”></div> <div></div> $(‘#foo’); <div id=”foo”></div> <div></div> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 10. jQuery Conference San Francisco Bay Area 2010 Finding Something // Select by class <div class=”myClass foo bar”></div> <div class=”baz myClass”></div> <div class=”bar”></div> $(‘.myClass’) <div class=”myClass foo bar”></div> <div class=”baz myClass”></div> <div class=”bar”></div> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 11. jQuery Conference San Francisco Bay Area 2010 Finding Something // Select by tag <ul> <li>Apple</li> <li>Pear</li> </ul> $(“li”); <ul> <li>Apple</li> <li>Pear</li> </ul> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 12. jQuery Conference San Francisco Bay Area 2010 Finding Something in Context ‣ Entire Document $(‘div’) ‣ Scope your selector $(‘selector’, <context>) $(‘#table’).find(‘selector’) ‣ $(‘a’).click(function() { $(‘span’, this)... }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 13. jQuery Conference San Francisco Bay Area 2010 Demo! Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 14. jQuery Conference San Francisco Bay Area 2010 Do Something Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 15. jQuery Conference San Francisco Bay Area 2010 Do Something <p>One</p> <p>Two</p> <p>Three</p> // Find Something $(‘p’) // Do Something $(‘p’).hide(); // Generic Syntax $(‘p’) . <Method Name> ( [PARAMETERS] ); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 16. jQuery Conference San Francisco Bay Area 2010 Showing and Hiding // HTML <p>One</p> <p>Two</p> <p>Three</p> // Show the elements $(‘p’).show(); // Hide the elements $(‘p’).hide(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 17. jQuery Conference San Francisco Bay Area 2010 Showing and Hiding // HTML <p>One</p> <p>Two</p> <p>Three</p> // Show the elements $(‘p’).show(); // Hide the elements $(‘p’).hide(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 18. jQuery Conference San Francisco Bay Area 2010 Iteration <p>One</p> <p>Two</p> <p>Three</p> $(‘p’).each(function() { // Operates on each p individually var rand; rand = Math.floor( Math.random() * 1 ); if(rand > 1) { $(this).hide(); } }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 19. jQuery Conference San Francisco Bay Area 2010 Iteration <p>One</p> <p>Two</p> <p>Three</p> $(‘p’).each(function() { // Operates on each p individually var rand; rand = Math.floor( Math.random() * 1 ); if(rand > 1) { $(this).hide(); } }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 20. jQuery Conference San Francisco Bay Area 2010 Iteration <p>One</p> <p>Two</p> <p>Three</p> $(‘p’).each(function() { // Operates on each p individually var rand; rand = Math.floor( Math.random() * 1 ); if(rand > 1) { $(this).hide(); } }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 21. jQuery Conference San Francisco Bay Area 2010 Styling // HTML <p>One</p> <p class=”foo”>Two</p> <p>Three</p> $(‘p’).addClass(‘enabled’); $(‘p’).removeClass(‘foo’); $(‘p’).toggleClass(‘foo’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 22. jQuery Conference San Francisco Bay Area 2010 Styling // HTML <p class=”enabled”>One</p> <p class=”enabled foo”>Two</p> <p class=”enabled”>Three</p> $(‘p’).addClass(‘enabled’); $(‘p’).removeClass(‘foo’); $(‘p’).toggleClass(‘foo’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 23. jQuery Conference San Francisco Bay Area 2010 Styling // HTML <p class=”enabled”>One</p> <p class=”enabled”>Two</p> <p class=”enabled”>Three</p> $(‘p’).addClass(‘enabled’); $(‘p’).removeClass(‘foo’); $(‘p’).toggleClass(‘foo’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 24. jQuery Conference San Francisco Bay Area 2010 Styling // HTML <p class=”enabled foo”>One</p> <p class=”enabled foo”>Two</p> <p class=”enabled foo”>Three</p> $(‘p’).addClass(‘enabled’); $(‘p’).removeClass(‘foo’); $(‘p’).toggleClass(‘foo’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 25. jQuery Conference San Francisco Bay Area 2010 Method Chaining Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 26. jQuery Conference San Francisco Bay Area 2010 Method Chaining $(‘tr:odd’).addClass(‘odd’) .find(‘td.company’) .addClass(‘companyName’); $(‘tr:odd’).addClass(‘odd’) .find(‘td.company’) .addClass(‘companyName’) .end(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 27. jQuery Conference San Francisco Bay Area 2010 Method Chaining $(‘tr’) .filter(‘:odd’) .addClass(‘odd’) .end() .find(‘td.company’) .addClass(‘companyName’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 28. jQuery Conference San Francisco Bay Area 2010 DOM Manipulation Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 29. jQuery Conference San Francisco Bay Area 2010 Creating Elements // New in 1.4 $("<div/>", { class: "test", text: "Click me!", click: function(){ $(this).toggleClass("test"); } }); // Clicking toggles the class <div class=”test”>Click me!</div> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 30. jQuery Conference San Francisco Bay Area 2010 Inserting Elements // Before <p>Apple</p> <p>Orange</p> $(‘p’).after(‘<img src=”logo.png” />’); // After <p>Apple</p> <img src=”logo.png /> <p>Orange</p> <img src=”logo.png /> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 31. jQuery Conference San Francisco Bay Area 2010 Inserting Elements // Before <p id=”apple”>Apple</p> <p id=”orange”>Orange</p> $(‘<img src=”apple.png” />’).prependTo(‘#apple’); $(‘<img src=”orange.png” />’).appendTo(‘#orange’); // After <p id=”apple”><img src=”apple.png” />Apple</p> <p id=”orange”>Orange<img src=”orange.png” /></p> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 32. jQuery Conference San Francisco Bay Area 2010 Removing Elements // Before <div> <p>Red</p> <p>Green</p> </div> // Removing Elements Directly $(‘p’).remove(); // After <div> </div> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 33. jQuery Conference San Francisco Bay Area 2010 Wrapping Elements // Before <p>Hello world</p> <p>Foo bar</p> $(‘p’).wrap(‘<div></div>’); // After <div><p>Hello world</p></div> <div><p>Foo bar</p></div> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 34. jQuery Conference San Francisco Bay Area 2010 Unwrapping Elements (new in 1.4+) // Before <div><p>Hello world</p></div> <div><p>Foo bar</p></div> //Individually $(‘p’).unwrap(); // After <p>Hello world</p> <p>Foo bar</p> Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 35. jQuery Conference San Francisco Bay Area 2010 Binding Events Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 36. jQuery Conference San Francisco Bay Area 2010 Click Event // HTML <p>One</p> <p>Two</p> <p>Three</p> $(‘p’).click(function(event) { $(this).css(‘color’, ‘red’); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 37. jQuery Conference San Francisco Bay Area 2010 Click Event // HTML <p>One</p> <p style=”color: red”>Two</p> // Clicked! <p>Three</p> $(‘p’).click(function(event) { $(this).css(‘color’, ‘red’); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 38. jQuery Conference San Francisco Bay Area 2010 Hover Pseudo Event // HTML <p>One</p> <p>Two</p> <p>Three</p> $(‘p’).hover(function(event) { $(this).css(‘color’, ‘red’); }, function() { $(this).css(‘color’, ‘’); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 39. jQuery Conference San Francisco Bay Area 2010 Binding & Unbinding // HTML <p>One</p> <p>Two</p> <p>Three</p> // Add event $(‘p’).bind(‘click’,function(event) { $(this).css(‘color’, ‘red’); }); // Remove event $(‘p’).unbind(‘click’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 40. jQuery Conference San Francisco Bay Area 2010 Binding Events with .bind() // Binding an event $('a.tab').bind('click',function(e){ // event handling code $(this).css(‘color’, ‘red’); }); // Unbinding an event  $('a.tab').unbind('click'); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 41. jQuery Conference San Francisco Bay Area 2010 Binding Events // Bind an event to execute once $('a.tab').one('click',function(e){ // event handling code   $(this).css(‘color’,‘red’); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 42. jQuery Conference San Francisco Bay Area 2010 Demo! Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 43. jQuery Conference San Francisco Bay Area 2010 Ajax Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 44. jQuery Conference San Francisco Bay Area 2010 Making a Request $.get(‘page.php’, function(data) { $(data).appendTo(‘body’); }, ‘html’); var data = { fname: ‘Jonathan’ }; $.post(‘page.php’, data, function(data) { $(data).appendTo(‘body’); }, ‘html’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 45. jQuery Conference San Francisco Bay Area 2010 Making a Request JSON // Response {“names”: [“Jonathan”, “Mike”, “Rob”], “states”: {“NE” : “Nebraska”}, “year” : “2010” } $.getJSON(‘page.php’, function(json) { $(‘body’).append( json.names[0] ); $(‘body’).append( json.states.NE ); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 46. jQuery Conference San Francisco Bay Area 2010 Making a Request JSON // Response { “names”: [“Jonathan”, “Mike”, “Rob”] } $.getJSON(‘page.php’, function(json) { $.each(json.names, function(i, val) { $(‘body’).append( val ); }); }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 47. jQuery Conference San Francisco Bay Area 2010 Writing Your First Plugin Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 48. jQuery Conference San Francisco Bay Area 2010 Writing your first Plugin $.fn.elementCount = function() { alert(‘Element count: ’ + this.length); }; $(‘p’).elementCount(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 49. jQuery Conference San Francisco Bay Area 2010 Plugins and Iteration $.fn.elementCount = function() { // this is a jQuery Object this.each(function(i) { $(this).html($(this).html() +‘ ‘+ i); }); }; $(‘p’).elementCount(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 50. jQuery Conference San Francisco Bay Area 2010 Plugins and Chaining $.fn.elementCount = function() { // this is a jQuery Object return this.each(function(i) { $(this).html($(this).html() +‘ ‘+ i); }); }; $(‘p’).elementCount().addClass(‘active’);; Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 51. jQuery Conference San Francisco Bay Area 2010 Plugins and Chaining // Plugin is required to return this $.fn.stPatricks = function() { return this.css(‘color’, ‘green’); }; $(‘p’).stPatricks().addClass(‘active’); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 52. jQuery Conference San Francisco Bay Area 2010 The Plugin Pattern Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 53. jQuery Conference San Francisco Bay Area 2010 The Plugin Pattern (function($) { $.fn.elementCount = function() { return this.each(function(i) { $(this).html($(this).html() +‘ ‘+ i); }); }; })(jQuery); $(‘p’).elementCount(); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 54. jQuery Conference San Francisco Bay Area 2010 The Plugin Pattern (function($) { $.fn.elementCount = function(options) { return this.each(function(i) { var j = i + options.start; $(this).html($(this).html() +‘ ‘+ j); }); }; })(jQuery); $(‘p’).elementCount({start: 10}); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 55. jQuery Conference San Francisco Bay Area 2010 The Plugin Pattern (function($) { $.fn.elementCount = function(options) { var j; if ( $.isFunction(options.begin) ) { options.begin(); } return this.each(function(i) { j = i + options.start; $(this).html($(this).html() +‘ ‘+ j); }); }; })(jQuery); $(‘p’).elementCount( start: 10, begin: function() {alert(‘BEGIN!’)} }); Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 56. jQuery Conference San Francisco Bay Area 2010 Demo! Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY
  • 57. jQuery Conference San Francisco Bay Area 2010 Thank You! Mike Hostetler @mikehostetler http://mike-hostetler.com Copyright © 2010 appendTo, LLC. THE jOUERY COMPANY