SlideShare une entreprise Scribd logo
1  sur  128
Télécharger pour lire hors ligne
jQuery <3 Developers
Overview
• Who, what, why of jQuery
• Core concepts of jQuery
• API overview & tips
• Plugin design pattern
• News
• Live demo
Quick survey first
Who?
Who?
Who?

     reddit.com        whitehouse.gov              overstock.com
      espn.com         microsoft.com                  time.com
      ibm.com           amazon.com                 capitalone.com
stackoverflow.com         netflix.com                wordpress.com
      boxee.tv            bing.com                     dell.com
        bit.ly          monster.com                  twitter.com
    twitpic.com            tv.com                       w3.org

           http://trends.builtwith.com/javascript/jquery
What?
      jQuery is a JavaScript library.

• Selector engine: Sizzle
• DOM manipulation
• Events
• Effects
• Ajax
What does that mean?
It means no more of this
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';
        }
    }
}
jQuery simpli es


jQuery('table tr:nth-child(odd)').addClass('odd');
jQuery simpli es

  jQuery function

jQuery('table tr:nth-child(odd)').addClass('odd');
jQuery simpli es

  jQuery function

jQuery('table tr:nth-child(odd)').addClass('odd');


                CSS expression
jQuery simpli es

  jQuery function             jQuery method
jQuery('table tr:nth-child(odd)').addClass('odd');


                CSS expression
jQuery simpli es


jQuery('table tr:nth-child(odd)').addClass('odd');
Why use jQuery
•   Helps us to simplify and speed up web development

•   Allows us to avoid common headaches associated
    with browser development

•   Provides a large pool of plugins

•   Large and active community

•   Tested on 50 browsers, 11 platforms

•   For both coder and designer (we don't discriminate)
Why use jQuery
•   Helps us to simplify and speed up web development

•   Allows us to avoid common headaches associated
    with browser development

•   Provides a large pool of plugins

•   Large and active community

•   Tested on 50 browsers, 11 platforms

•   For both coder and designer (we don't discriminate)
Help!
APIs            Blogs, tutorials, screencasts,
 docs.jquery.com        plugins, development sprints
  api.jquery.com
 visualjquery.com
                                          Google Groups
                                              jquery-en
  Twitter                                    jquery-dev
 @jquery              Help!                 jquery-ui-en
@jquerysites                               jquery-ui-dev
 @jqueryui                                  jquery-a11y
                      IRC channel
               irc.freenode.net/#jquery
APIs         Blogs, tutorials, screencasts,
 docs.jquery.com     plugins, development sprints
  api.jquery.com
 visualjquery.com
                                       Google Groups
                                           jquery-en
  Twitter                                 jquery-dev
 @jquery            Help!                jquery-ui-en
@jquerysites                            jquery-ui-dev
 @jqueryui                               jquery-a11y
                   IRC channel
            irc.freenode.net/#jquery
Concept 1:
knowing the jQuery
 parameter types
• CSS selectors & custom CSS expressions
• HTML
• DOM elements
• A function (shortcut for DOM ready)
jQuery(‘div’) & jQuery(‘:first’)


   • CSS selectors & custom CSS expressions
   • HTML
   • DOM elements
   • A function (shortcut for DOM ready)
jQuery(‘<li><a href=”#”>link</a></li>’)


    • CSS selectors jQuery(‘:first’)
    jQuery(‘div’) &
                    & custom CSS expressions


    • HTML
    • DOM elements
    • A function (shortcut for DOM ready)
jQuery(document) or jQuery(document.createElement(‘a’))




      • CSS selectors jQuery(‘:first’)
      jQuery(‘div’) &
                      & custom CSS expressions


      • HTML
      jQuery(‘<li><a href=”#”>link</a></li>’)


      • DOM elements
      • A function (shortcut for DOM ready)
jQuery(function(){}) =
jQuery(document).ready(function(){})

   • CSS selectors jQuery(‘:first’)
   jQuery(‘div’) &
                   & custom CSS expressions


   • HTML
   jQuery(‘<li><a href=”#”>link</a></li>’)


   • DOM elements
   jQuery(document) or jQuery(document.createElement(‘a’))


   • A function (shortcut for DOM ready)
• CSS selectors jQuery(‘:first’)
jQuery(‘div’) &
                & custom CSS expressions


• HTML
jQuery(‘<li><a href=”#”>link</a></li>’)


• DOM elements
jQuery(document) or jQuery(document.createElement(‘a’))


• A function (shortcut for DOM ready)
       jQuery(function(){}) =
jQuery(document).ready(function(){})
Concept 2:
nd something,
do something
<!DOCTYPE html>
<html>
<body>
  <ul id="nav">
    <li><a>home</a></li>
    <li><a>about</a></li>
  </ul>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id="nav">
    <li><a>home</a></li>
    <li><a>about</a></li>
  </ul>
<script src="jquery.js"></script>
</body>
</html>
<!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('#nav li');
</script>
</body>
</html>
<!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('#nav li').addClass('item');
</script>
</body>
</html>
Concept 3:
create something,
  do something
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
  </ul>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
  </ul>
<script src=”jquery.js”></script>
<script>
  jQuery(‘<li>home</li>’);
  jQuery(‘<li>about</li>’);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li>home</li>
    <li>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
  jQuery(‘<li>home</li>’)
➥.appendTo(‘#nav’);
  jQuery(‘<li>about</li>’)
➥.appendTo(‘#nav’);
</script>
</body>
</html>
Insi de
   tip

  createDocumentFragment
Insi de
   tip

  createDocumentFragment

    (IE6 || IE7) &&
    innerHTML && HTML5
    == fail
Concept 4:
chaining & operating
<!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>
<!DOCTYPE html>
<html>
    1
<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>
1 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>
<!DOCTYPE html>
<html>
    1
<body>
  <ul id='nav'>
    <li class=”item”><a href=”/home”>home</a></li>
    <li class=”item”><a href=”/about”>about</a></li>
  </ul>      2
<script src=”jquery.js”></script>
<script>
1 jQuery(‘ul’).attr(‘id’, ‘nav’);
                                    2
  jQuery(‘#nav li’).addClass(‘item’);
  jQuery(‘#nav a’).each(function () {
    jQuery(this).attr(‘href’, ‘/’+jQuery(this).text());
  });
</script>
</body>
</html>
<!DOCTYPE html>
<html>
    1
<body>
  <ul id='nav'>                3
    <li class=”item”><a href=”/home”>home</a></li>
    <li class=”item”><a href=”/about”>about</a></li>
  </ul>      2
<script src=”jquery.js”></script>
<script>
1 jQuery(‘ul’).attr(‘id’, ‘nav’);
                                    2
  jQuery(‘#nav li’).addClass(‘item’);
  jQuery(‘#nav a’).each(function () {
    jQuery(this).attr(‘href’, ‘/’+jQuery(this).text());
  });
</script>
              3
</body>
</html>
<!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>
<!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’)
    .find(‘li’)
    .addClass(‘item’)
    .find(‘a’)
    .each(function () {
       jQuery(this).attr(‘href’, ‘/’+jQuery(this).text());
    });
</script>
</body>
</html>
jQuery returns itself
containing the current
   DOM collection
Concept 5:
 understanding
implicit iteration
<!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’)
    .find(‘li’)
    .addClass(‘item’)
    .find(‘a’)
    .each(function () {
       jQuery(this).attr(‘href’, ‘/’+jQuery(this).text());
    });
</script>
</body>
</html>
<!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’)
    .find(‘li’)
    .addClass(‘item’)
    .find(‘a’)
    .each(function () {
       jQuery(this).attr(‘href’, ‘/’+jQuery(this).text());
    });
</script>
</body>
</html>
Review

• Knowing the jQuery parameter types
• Find something, do something
• Create something, do something
• Chaining & Operating
• Understanding Implicit Iteration
“What about the
bling function?”
jQuery == $
$ == jQuery
$ is an alias to jQuery
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
  jQuery(‘li’).addClass(‘item’);
</script>
</body>
</html>
<!DOCTYPE html>
 <html>
 <body>
   <ul id='nav'>
     <li class=”item”>home</li>
     <li class=”item”>about</li>
   </ul>
 <script src=”jquery.js”></script>
 <script>
jQuery(‘li’).addClass(‘item’);
 </script>
 </body>
 </html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
 $(‘li’).addClass(‘item’);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
  $(‘li’).addClass(‘item’);
</script>
</body>
</html>
More than ready
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
  $(‘li’).addClass(‘item’);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
$(document).ready(function () {
  $(‘li’).addClass(‘item’);
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
  <ul id='nav'>
    <li class=”item”>home</li>
    <li class=”item”>about</li>
  </ul>
<script src=”jquery.js”></script>
<script>
$(document).ready(function () {
  $(‘li’).addClass(‘item’);
});
</script>
</body>
</html>
app.js
$(document).ready(function () {
  $(‘li’).addClass(‘item’);
});
app.js
$(document).ready(function () {
  $(‘li’).addClass(‘item’);
});
app.js
$(function () {
  $(‘li’).addClass(‘item’);
});
app.js
jQuery(function ($) {
  $(‘li’).addClass(‘item’);
});
Tip

 Include jQuery after styles
jQuery API overview
•   Core

•   Selectors

•   Attributes

•   Traversing

•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           jQuery()

•   Selectors      each()
                   size()
•   Attributes     eq()
                   get()
•   Traversing     index()


•   Manipulation   length
                   selector
•   CSS            context


•   Events         data()
                   removeData()

•   Effects        queue()
                   dequeue()

•   Ajax           jQuery.fn.extend()

•   Utilities      jQuery.extend()
                   jQuery.noConflict()
•   Core           jQuery()

•   Selectors      each()
                   size()
•   Attributes     eq()
                   get()
•   Traversing     index()


•   Manipulation   length
                   selector
•   CSS            context


•   Events         data()
                   removeData()

•   Effects        queue()
                   dequeue()

•   Ajax           jQuery.fn.extend()

•   Utilities      jQuery.extend()
                   jQuery.noConflict()
•   Core           <!DOCTYPE html>

•   Selectors
                   <html>
                   <body>
•   Attributes
                   <p>Element Node</p>
•   Traversing

•
                   <script src="jquery.js">
    Manipulation   </script>

•   CSS            <script>
                   alert($('p').get(0).nodeName);
•   Events         </script>

•   Effects        </body>

•   Ajax           </html>


•   Utilities                    http://jsbin.com/ibito/edit
•   Core           <!DOCTYPE html>

•   Selectors
                   <html>
                   <body>
•   Attributes
                   <p>Element Node</p>
•   Traversing

•
                   <script src="jquery.js">
    Manipulation   </script>

•   CSS            <script>
                   alert($('p').get(0).nodeName);
•   Events         alert($('p')[0].nodeName);
                   </script>
•   Effects

•   Ajax           </body>
                   </html>
•   Utilities                    http://jsbin.com/idiyi/edit
•   Core

•   Selectors

•   Attributes

•   Traversing

•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors

•   Attributes

•   Traversing

•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes

•   Traversing

•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing

•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing
                   $(‘a[title]’)
•   Manipulation

•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing
                   $(‘a[title]’)
•   Manipulation
                   $(‘a[title][hash*=”foo”]’)
•   CSS

•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing
                   $(‘a[title]’)
•   Manipulation
                   $(‘a[title][hash*=”foo”]’)
•   CSS
                   $(‘a:first[hash*=”foo”]’)
•   Events

•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing
                   $(‘a[title]’)
•   Manipulation
                   $(‘a[title][hash*=”foo”]’)
•   CSS
                   $(‘a:first[hash*=”foo”]’)
•   Events
                   $(‘.header, .footer’)
•   Effects

•   Ajax

•   Utilities
•   Core           $(‘#nav li.contact’)

•   Selectors      $(‘:visible’)

•   Attributes     $(‘:radio:enabled:checked’)

•   Traversing
                   $(‘a[title]’)
•   Manipulation
                   $(‘a[title][hash*=”foo”]’)
•   CSS
                   $(‘a:first[hash*=”foo”]’)
•   Events
                   $(‘.header, .footer’)
•   Effects
                   $(‘.header, .footer’, ‘#main’)
•   Ajax

•   Utilities
Insi de
   tip
             Performance
          getElementById

          getElementsByTagName

          getElementsByClassName

          querySelectorAll
Insi de
   tip
             Performance

                   ry s elec tors
             Que
          getElementById
           j
               fail s ilen tly,
          getElementsByTagName
                         SS d oes!
           ju st l ike C
          getElementsByClassName

          querySelectorAll
•   Core           add()            eq()

•
                   children()       filter()
    Selectors      closest()        is()

•   Attributes
                   contents()
                   find()
                                    map()
                                    not()

•   Traversing     next()
                   nextAll()
                                    slice()


•   Manipulation   offsetParent()
                   parent()
•   CSS            parents()
                   prev()
•   Events         prevAll()
                   siblings()
•   Effects
                   andSelf()
•   Ajax           end()

•   Utilities
Ne•wCore
     in            add()            eq()

  • .3
                   children()       filter()
    Selectors
 1 Attributes
  •
                   closest()
                   contents()
                                    is()
                                    map()
                   find()           not()

  • Traversing     next()
                   nextAll()
                                    slice()


  • Manipulation   offsetParent()
                   parent()
  • CSS            parents()
                   prev()
  • Events         prevAll()
                   siblings()
  • Effects        andSelf()
  • Ajax           end()

  • Utilities
• Core            add()            eq()

• Selectors
                  children()       filter()
                  closest()        is()

• Searches down
   Attributes
                  contents()
                  find()
                                   map()
                                   not()

• Traversing      next()
                  nextAll()
                                   slice()


• Manipulation    offsetParent()
                  parent()
• CSS             parents()
                  prev()
• Events          prevAll()
                  siblings()
• Effects         andSelf()
• Ajax            end()

• Utilities
•   Core           add()
                       Filters across
                                        eq()

•
                   children()           filter()
    Selectors      closest()            is()

•   Attributes
                   contents()
                   find()
                                        map()
                                        not()

•   Traversing     next()
                   nextAll()
                                        slice()


•   Manipulation   offsetParent()
                   parent()
•   CSS            parents()
                   prev()
•   Events         prevAll()
                   siblings()
•   Effects
                   andSelf()
•   Ajax           end()

•   Utilities
•   Core           add()            eq()

•
                   children()       filter()
    Selectors      closest()        is()

•   Attributes
                   contents()
                   find()
                                    map()
                                    not()

•   Traversing     next()
                   nextAll()
                                    slice()


•   Manipulation   offsetParent()
                   parent()
•   CSS            parents()
                   prev()
•   Events         prevAll()
                   siblings()
•   Effects
                   andSelf()
•   Ajax           end()

•   Utilities
•   Core           <!DOCTYPE html><html><body>

•
                   <ul>
    Selectors        <li><a>one</a></li>

•   Attributes
                     <li><a>two</a></li>
                     <li><a>three</a></li>

•   Traversing     </ul>
                   <script src="jquery.js">
•   Manipulation   </script>
                   <script>
•   CSS            $('a').click(function () {
                     alert( $(this)
•   Events              .parent()
                        .prevAll()
•   Effects
                     )
                        .length

•   Ajax           });

•
                   </script>
    Utilities      </body></html>http://jsbin.com/ubuhe/edit
•   Core           ready()          blur()

•
                                    change()
    Selectors      bind()           click()

•   Attributes
                   one()
                   trigger()
                                    dbclick()
                                    focus()

•   Traversing     triggerHandler() keydown()
                   unbind()         keypress()
•   Manipulation
                   live()
                                    keyup()
                                    mousedown()
•   CSS            die()            mousenter()
                                    mouseleave()
•   Events         hover()
                   toggle()
                                    mouseout()
                                    mouseup()
•   Effects
                   load()
                                    resize()
                                    scroll()
•   Ajax           unload()         select()

•
                   error()          submit()
    Utilities
•   Core           ready()             blur()
                       IE fires on blur
•
                                       change()
    Selectors      bind()              click()

•   Attributes
                   one()
                   trigger()
                                       dbclick()
                                       focus()

•   Traversing     triggerHandler() keydown()
                   unbind()            keypress()
•   Manipulation
                   live()
                                       keyup()
                                       mousedown()
•   CSS            die()               mousenter()
                                       mouseleave()
•   Events         hover()
                   toggle()
                                       mouseout()
                                       mouseup()
•   Effects
                   load()
                                       resize()
                                       scroll()
•   Ajax           unload()            select()

•
                   error()             submit()
    Utilities
•   Core           ready()          blur()

•
                                    change()
    Selectors      bind()           click()

•   Attributes
                   one()
                   trigger()
                                    dbclick()
                                    focus()

•   Traversing     triggerHandler() keydown()
                   unbind()         keypress()
•   Manipulation
                   live()
                                    keyup()
                                    mousedown()
•   CSS            die()            mousenter()
                                    mouseleave()
•   Events         hover()
                   toggle()
                                    mouseout()
                                    mouseup()
•   Effects
                   load()
                                    resize()
                                    scroll()
•   Ajax           unload()         select()

•
                   error()          submit()
    Utilities
•   Core           <!DOCTYPE html>

•
                   <html>
    Selectors      <body>

•   Attributes     <p>1. click</p>

•   Traversing
                   <p>2. click</p>


•   Manipulation   <script src="jquery.js"></script>
                   <script>

•   CSS
                   $(‘p’).bind(‘click’, function(){

•   Events          $(this).after(‘<p>’ +
                    ➥ $(this).text()+‘ clicked</p>’);
•   Effects        });


•   Ajax           </script>
                   </body>
•   Utilities      </html>           http://jsbin.com/ededi/edit
•   Core           <!DOCTYPE html>

•
                   <html>
    Selectors      <body>

•   Attributes     <p>1. click</p>

•   Traversing
                   <p>2. click</p>


•   Manipulation   <script src="jquery.js"></script>
                   <script>

•   CSS
                   $(‘p’).live(‘click’, function(){

•   Events          $(this).after(‘<p>’ +
                    ➥ $(this).text()+‘ clicked</p>’);
•   Effects        });


•   Ajax           </script>
                   </body>
•   Utilities      </html>           http://jsbin.com/ihalu/edit
•   Core           $.fx.off

•   Selectors      show()
•   Attributes     hide()
                   toggle()
•   Traversing
                   slideDown()
•   Manipulation   slideUp()

•   CSS            slideToggle()

•   Events         fadeIn()
                   fadeOut()
•   Effects        fadeTo()

•   Ajax           animate()
•   Utilities      stop()
• Core control                    ew in
Blanket FX       $.fx.off        N
• Selectors      show()              1.3
• Attributes     hide()
                 toggle()
• Traversing     slideDown()
• Manipulation   slideUp()

• CSS            slideToggle()

• Events         fadeIn()
                 fadeOut()
• Effects        fadeTo()

• Ajax           animate()
• Utilities      stop()
•   Core           $.fx.off

•   Selectors      show()
•   Attributes     hide()
                   toggle()
•   Traversing
                   slideDown()
•   Manipulation   slideUp()

•   CSS            slideToggle()

•   Events         fadeIn()
                   fadeOut()
•   Effects        fadeTo()

•   Ajax           animate()
•   Utilities      stop()
•   Core           <!DOCTYPE html><html><head>
                   <style>
•   Selectors      div {background:#bca; width:100px;
                   border:1px solid green;}
•   Attributes     </style>
                   </head>
•   Traversing     <body>
                   <div id="block">Hello!</div>
•   Manipulation   <script src="jquery.js"></script>
                   <script>

•   CSS
                   $(‘#block’).animate({

•   Events         ! width: ‘70%’,
                   ! opacity: 0.4,

•   Effects        ! marginLeft: ‘0.6in’,
                   ! fontSize: ‘3em’,

•   Ajax
                   ! borderWidth: ‘10px’
                   }, 1500);
                                   http://jsbin.com/oroto/edit
•   Utilities      </script></body></html>
•   Core           $.ajax()        ajaxCompete()

•   Selectors
                   $.get()
                   $.post()
                                   ajaxError()
                                   ajaxSend()
•   Attributes     $.getJSON()
                   $.getScript()
                                   ajaxStart()
                                   ajaxStop()
•   Traversing     $.ajaxSetup()   ajaxSuccess()

•   Manipulation   load()

•   CSS
                   serialize()
•   Events         serializeArray()

•   Effects
•   Ajax

•   Utilities
•   Core           $.ajax()        ajaxCompete()

•   Selectors
                   $.get()
                   $.post()
                                   ajaxError()
                                   ajaxSend()
•   Attributes     $.getJSON()
                   $.getScript()
                                   ajaxStart()
                                   ajaxStop()
•   Traversing     $.ajaxSetup()   ajaxSuccess()

•   Manipulation   load()

•   CSS
                   serialize()
•   Events         serializeArray()

•   Effects
•   Ajax

•   Utilities
•   Core           <!DOCTYPE html><html><body>

•
                   <script src="jquery.js">
    Selectors      </script>

•   Attributes
                   <script>


•   Traversing     $.getJSON("http://twitter.com/
                   statuses/user_timeline.json?

•   Manipulation   screen_name=rem&callback=?",
                   function(data){
•   CSS              $.each(data,function(i,tweet){
                       $('<p/>').html
•   Events         (tweet.text).appendTo('body');
                       if ( i == 30 ) return false;
•   Effects          });

•
                   });
    Ajax           </script></body></html>

•   Utilities                      http://jsbin.com/acisi/edit
Plugins
What’s a plugin?
A plugin is nothing more than a custom
jQuery method created to extend the
functionality of the jQuery object


$(‘ul’).myPlugin()
Plugin design in 6 steps
Step 1:
create a private
scope for $ alias
<!DOCTYPE html><html><body>
<script src=”jquery.js”></script>
<script>
(function ($) {

})(jQuery);
</script></body></html>
Step 2:
 attach plugin to fn
alias (aka prototype)
<!DOCTYPE html><html><body>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  $(this).text(
     $(this).text().replace(/hate/g, ‘love’)
  );
}; // end of plugin
})(jQuery);
</script></body></html>
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  $(this).text(
     $(this).text().replace(/hate/g, ‘love’)
  );
}; // end of plugin
})(jQuery);

$(‘p’).notHate();
</script></body></html>
Step 3:
add implicit iteration
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g, ‘love’)
    );
  });
}; // end of plugin
})(jQuery);

$(‘p’).notHate();
</script></body></html>
Step 4:
enable chaining
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g, ‘love’)
    );
  });
}; // end of plugin
})(jQuery);

$(‘p’).notHate().hide();
</script></body></html>
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
 this == jQuery
(function ($) {
$.fn.notHate = function () {
  return this.each(function () {
     $(this).text(
        $(this).text().replace(/hate/g, ‘love’)
     );
  });
}; // end of plugin
})(jQuery);

$(‘p’).notHate().hide();
</script></body></html>
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
 this == jQuery
(function ($) {
$.fn.notHate = function () {
  return this.each(function () {
     $(this).text(
        $(this).text().replace(/hate/g, ‘love’)
     );
  });
}; // end of == DOM element
           this plugin
})(jQuery);

$(‘p’).notHate().hide();
</script></body></html>
Step 5:
add default options
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g,
       ➥ $.fn.notHate.defaults.text)
    );
  });
}; // end of plugin
$.fn.notHate.defaults = {text:‘love’};
})(jQuery);

$(‘p’).notHate();
</script></body></html>
Step 6:
add custom options
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function () {
  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g,
       ➥ $.fn.notHate.defaults.text)
    );
  });
}; // end of plugin
$.fn.notHate.defaults = {text:‘love’};
})(jQuery);

$(‘p’).notHate({text: ‘love-love-love’});
</script></body></html>
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function (options) {
  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g,
       ➥ $.fn.notHate.defaults.text)
    );
  });
}; // end of plugin
$.fn.notHate.defaults = {text:‘love’};
})(jQuery);

$(‘p’).notHate({text: ‘love-love-love’});
</script></body></html>
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function (options) {
  var settings = $.extend({},
  ➥ $.fn.notHate.defaults, options);

  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g,
       ➥ $.fn.notHate.defaults.text)
    );
  });
}; // end of plugin
$.fn.notHate.defaults = {text:‘love’};
})(jQuery);

$(‘p’).notHate({text: ‘love-love-love’});
</script></body></html>
<!DOCTYPE html><html><body>          http://jsbin.com/ifuga/edit
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src=”jquery.js”></script>
<script>
(function ($) {
$.fn.notHate = function (options) {
  var settings = $.extend({},
  ➥ $.fn.notHate.defaults, options);

  return this.each(function () {
    $(this).text(
       $(this).text().replace(/hate/g,
       ➥ settings.text)
    );
  });
}; // end of plugin
$.fn.notHate.defaults = {text:‘love’};
})(jQuery);

$(‘p’).notHate({text: ‘love-love-love’});
</script></body></html>
News

•   Four conferences next year:
    London, Boston, San Francisco and online
•   New plugin site
•   jQuery Forum (moving from Google Groups)
•   Mobile jQuery
Demo!
Remy Sharp @rem

jQuery team member
Co-author of O'Reilly
jQuery Cookbook
(due November 20th)


jqueryfordesigners.com
remysharp.com
Remy Sharp @rem

jQuery team member
Co-author of O'Reilly
jQuery Cookbook
(due November 20th)


jqueryfordesigners.com
                           ?
                         Questions
remysharp.com

Contenu connexe

Tendances

jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryGunjan Kumar
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 

Tendances (20)

jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery
jQueryjQuery
jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
jQuery
jQueryjQuery
jQuery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
jQuery
jQueryjQuery
jQuery
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 

Similaire à jQuery Loves Developers - Oredev 2009

Devdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for DevelopersDevdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for Developerscody lindley
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile IntroGonzalo Parra
 
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02careersblog
 
J query presentation
J query presentationJ query presentation
J query presentationakanksha17
 
J query presentation
J query presentationJ query presentation
J query presentationsawarkar17
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobileErik Duval
 
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 CombinationSean Burgess
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesMark Roden
 
The State of jQuery 2013
The State of jQuery 2013The State of jQuery 2013
The State of jQuery 2013Richard Worth
 
CT presentatie JQuery 7.12.11
CT presentatie JQuery 7.12.11CT presentatie JQuery 7.12.11
CT presentatie JQuery 7.12.11virtualsciences41
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)David Giard
 
jQuery - Web Engineering
jQuery - Web Engineering jQuery - Web Engineering
jQuery - Web Engineering adeel990
 

Similaire à jQuery Loves Developers - Oredev 2009 (20)

Devdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for DevelopersDevdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for Developers
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query presentation
J query presentationJ query presentation
J query presentation
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
20111014 mu me_j_querymobile
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
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 - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
The State of jQuery 2013
The State of jQuery 2013The State of jQuery 2013
The State of jQuery 2013
 
CT presentatie JQuery 7.12.11
CT presentatie JQuery 7.12.11CT presentatie JQuery 7.12.11
CT presentatie JQuery 7.12.11
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
 
jQuery for Seaside
jQuery for SeasidejQuery for Seaside
jQuery for Seaside
 
jQuery - Web Engineering
jQuery - Web Engineering jQuery - Web Engineering
jQuery - Web Engineering
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 

Plus de Remy Sharp

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Forget the Web
Forget the WebForget the Web
Forget the WebRemy Sharp
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction ImplementationRemy Sharp
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the newRemy Sharp
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for MobileRemy Sharp
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with WingsRemy Sharp
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the webRemy Sharp
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIsRemy Sharp
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIsRemy Sharp
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & FriendsRemy Sharp
 
jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009Remy Sharp
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 

Plus de Remy Sharp (20)

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Forget the Web
Forget the WebForget the Web
Forget the Web
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction Implementation
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
TwitterLib.js
TwitterLib.jsTwitterLib.js
TwitterLib.js
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
HTML5 JS APIs
HTML5 JS APIsHTML5 JS APIs
HTML5 JS APIs
 
jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009jQuery Loves Developers - SWDC2009
jQuery Loves Developers - SWDC2009
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 

Dernier

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Dernier (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

jQuery Loves Developers - Oredev 2009

  • 2. Overview • Who, what, why of jQuery • Core concepts of jQuery • API overview & tips • Plugin design pattern • News • Live demo
  • 6. Who? reddit.com whitehouse.gov overstock.com espn.com microsoft.com time.com ibm.com amazon.com capitalone.com stackoverflow.com netflix.com wordpress.com boxee.tv bing.com dell.com bit.ly monster.com twitter.com twitpic.com tv.com w3.org http://trends.builtwith.com/javascript/jquery
  • 7. What? jQuery is a JavaScript library. • Selector engine: Sizzle • DOM manipulation • Events • Effects • Ajax
  • 9. It means no more of this 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'; } } }
  • 10. jQuery simpli es jQuery('table tr:nth-child(odd)').addClass('odd');
  • 11. jQuery simpli es jQuery function jQuery('table tr:nth-child(odd)').addClass('odd');
  • 12. jQuery simpli es jQuery function jQuery('table tr:nth-child(odd)').addClass('odd'); CSS expression
  • 13. jQuery simpli es jQuery function jQuery method jQuery('table tr:nth-child(odd)').addClass('odd'); CSS expression
  • 14. jQuery simpli es jQuery('table tr:nth-child(odd)').addClass('odd');
  • 15. Why use jQuery • Helps us to simplify and speed up web development • Allows us to avoid common headaches associated with browser development • Provides a large pool of plugins • Large and active community • Tested on 50 browsers, 11 platforms • For both coder and designer (we don't discriminate)
  • 16. Why use jQuery • Helps us to simplify and speed up web development • Allows us to avoid common headaches associated with browser development • Provides a large pool of plugins • Large and active community • Tested on 50 browsers, 11 platforms • For both coder and designer (we don't discriminate)
  • 17. Help!
  • 18. APIs Blogs, tutorials, screencasts, docs.jquery.com plugins, development sprints api.jquery.com visualjquery.com Google Groups jquery-en Twitter jquery-dev @jquery Help! jquery-ui-en @jquerysites jquery-ui-dev @jqueryui jquery-a11y IRC channel irc.freenode.net/#jquery
  • 19. APIs Blogs, tutorials, screencasts, docs.jquery.com plugins, development sprints api.jquery.com visualjquery.com Google Groups jquery-en Twitter jquery-dev @jquery Help! jquery-ui-en @jquerysites jquery-ui-dev @jqueryui jquery-a11y IRC channel irc.freenode.net/#jquery
  • 20. Concept 1: knowing the jQuery parameter types
  • 21. • CSS selectors & custom CSS expressions • HTML • DOM elements • A function (shortcut for DOM ready)
  • 22. jQuery(‘div’) & jQuery(‘:first’) • CSS selectors & custom CSS expressions • HTML • DOM elements • A function (shortcut for DOM ready)
  • 23. jQuery(‘<li><a href=”#”>link</a></li>’) • CSS selectors jQuery(‘:first’) jQuery(‘div’) & & custom CSS expressions • HTML • DOM elements • A function (shortcut for DOM ready)
  • 24. jQuery(document) or jQuery(document.createElement(‘a’)) • CSS selectors jQuery(‘:first’) jQuery(‘div’) & & custom CSS expressions • HTML jQuery(‘<li><a href=”#”>link</a></li>’) • DOM elements • A function (shortcut for DOM ready)
  • 25. jQuery(function(){}) = jQuery(document).ready(function(){}) • CSS selectors jQuery(‘:first’) jQuery(‘div’) & & custom CSS expressions • HTML jQuery(‘<li><a href=”#”>link</a></li>’) • DOM elements jQuery(document) or jQuery(document.createElement(‘a’)) • A function (shortcut for DOM ready)
  • 26. • CSS selectors jQuery(‘:first’) jQuery(‘div’) & & custom CSS expressions • HTML jQuery(‘<li><a href=”#”>link</a></li>’) • DOM elements jQuery(document) or jQuery(document.createElement(‘a’)) • A function (shortcut for DOM ready) jQuery(function(){}) = jQuery(document).ready(function(){})
  • 28. <!DOCTYPE html> <html> <body> <ul id="nav"> <li><a>home</a></li> <li><a>about</a></li> </ul> </body> </html>
  • 29. <!DOCTYPE html> <html> <body> <ul id="nav"> <li><a>home</a></li> <li><a>about</a></li> </ul> <script src="jquery.js"></script> </body> </html>
  • 30. <!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('#nav li'); </script> </body> </html>
  • 31. <!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('#nav li').addClass('item'); </script> </body> </html>
  • 33. <!DOCTYPE html> <html> <body> <ul id='nav'> </ul> </body> </html>
  • 34. <!DOCTYPE html> <html> <body> <ul id='nav'> </ul> <script src=”jquery.js”></script> <script> jQuery(‘<li>home</li>’); jQuery(‘<li>about</li>’); </script> </body> </html>
  • 35. <!DOCTYPE html> <html> <body> <ul id='nav'> <li>home</li> <li>about</li> </ul> <script src=”jquery.js”></script> <script> jQuery(‘<li>home</li>’) ➥.appendTo(‘#nav’); jQuery(‘<li>about</li>’) ➥.appendTo(‘#nav’); </script> </body> </html>
  • 36. Insi de tip createDocumentFragment
  • 37. Insi de tip createDocumentFragment (IE6 || IE7) && innerHTML && HTML5 == fail
  • 39. <!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>
  • 40. <!DOCTYPE html> <html> 1 <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> 1 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>
  • 41. <!DOCTYPE html> <html> 1 <body> <ul id='nav'> <li class=”item”><a href=”/home”>home</a></li> <li class=”item”><a href=”/about”>about</a></li> </ul> 2 <script src=”jquery.js”></script> <script> 1 jQuery(‘ul’).attr(‘id’, ‘nav’); 2 jQuery(‘#nav li’).addClass(‘item’); jQuery(‘#nav a’).each(function () { jQuery(this).attr(‘href’, ‘/’+jQuery(this).text()); }); </script> </body> </html>
  • 42. <!DOCTYPE html> <html> 1 <body> <ul id='nav'> 3 <li class=”item”><a href=”/home”>home</a></li> <li class=”item”><a href=”/about”>about</a></li> </ul> 2 <script src=”jquery.js”></script> <script> 1 jQuery(‘ul’).attr(‘id’, ‘nav’); 2 jQuery(‘#nav li’).addClass(‘item’); jQuery(‘#nav a’).each(function () { jQuery(this).attr(‘href’, ‘/’+jQuery(this).text()); }); </script> 3 </body> </html>
  • 43. <!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>
  • 44. <!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’) .find(‘li’) .addClass(‘item’) .find(‘a’) .each(function () { jQuery(this).attr(‘href’, ‘/’+jQuery(this).text()); }); </script> </body> </html>
  • 45. jQuery returns itself containing the current DOM collection
  • 47. <!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’) .find(‘li’) .addClass(‘item’) .find(‘a’) .each(function () { jQuery(this).attr(‘href’, ‘/’+jQuery(this).text()); }); </script> </body> </html>
  • 48. <!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’) .find(‘li’) .addClass(‘item’) .find(‘a’) .each(function () { jQuery(this).attr(‘href’, ‘/’+jQuery(this).text()); }); </script> </body> </html>
  • 49. Review • Knowing the jQuery parameter types • Find something, do something • Create something, do something • Chaining & Operating • Understanding Implicit Iteration
  • 50. “What about the bling function?”
  • 53. $ is an alias to jQuery
  • 54. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> jQuery(‘li’).addClass(‘item’); </script> </body> </html>
  • 55. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> jQuery(‘li’).addClass(‘item’); </script> </body> </html>
  • 56. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> $(‘li’).addClass(‘item’); </script> </body> </html>
  • 57. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> $(‘li’).addClass(‘item’); </script> </body> </html>
  • 59. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> $(‘li’).addClass(‘item’); </script> </body> </html>
  • 60. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> $(document).ready(function () { $(‘li’).addClass(‘item’); }); </script> </body> </html>
  • 61. <!DOCTYPE html> <html> <body> <ul id='nav'> <li class=”item”>home</li> <li class=”item”>about</li> </ul> <script src=”jquery.js”></script> <script> $(document).ready(function () { $(‘li’).addClass(‘item’); }); </script> </body> </html>
  • 62. app.js $(document).ready(function () { $(‘li’).addClass(‘item’); });
  • 63. app.js $(document).ready(function () { $(‘li’).addClass(‘item’); });
  • 64. app.js $(function () { $(‘li’).addClass(‘item’); });
  • 65. app.js jQuery(function ($) { $(‘li’).addClass(‘item’); });
  • 66. Tip Include jQuery after styles
  • 68. Core • Selectors • Attributes • Traversing • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 69. Core jQuery() • Selectors each() size() • Attributes eq() get() • Traversing index() • Manipulation length selector • CSS context • Events data() removeData() • Effects queue() dequeue() • Ajax jQuery.fn.extend() • Utilities jQuery.extend() jQuery.noConflict()
  • 70. Core jQuery() • Selectors each() size() • Attributes eq() get() • Traversing index() • Manipulation length selector • CSS context • Events data() removeData() • Effects queue() dequeue() • Ajax jQuery.fn.extend() • Utilities jQuery.extend() jQuery.noConflict()
  • 71. Core <!DOCTYPE html> • Selectors <html> <body> • Attributes <p>Element Node</p> • Traversing • <script src="jquery.js"> Manipulation </script> • CSS <script> alert($('p').get(0).nodeName); • Events </script> • Effects </body> • Ajax </html> • Utilities http://jsbin.com/ibito/edit
  • 72. Core <!DOCTYPE html> • Selectors <html> <body> • Attributes <p>Element Node</p> • Traversing • <script src="jquery.js"> Manipulation </script> • CSS <script> alert($('p').get(0).nodeName); • Events alert($('p')[0].nodeName); </script> • Effects • Ajax </body> </html> • Utilities http://jsbin.com/idiyi/edit
  • 73. Core • Selectors • Attributes • Traversing • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 74. Core $(‘#nav li.contact’) • Selectors • Attributes • Traversing • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 75. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes • Traversing • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 76. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 77. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing $(‘a[title]’) • Manipulation • CSS • Events • Effects • Ajax • Utilities
  • 78. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing $(‘a[title]’) • Manipulation $(‘a[title][hash*=”foo”]’) • CSS • Events • Effects • Ajax • Utilities
  • 79. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing $(‘a[title]’) • Manipulation $(‘a[title][hash*=”foo”]’) • CSS $(‘a:first[hash*=”foo”]’) • Events • Effects • Ajax • Utilities
  • 80. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing $(‘a[title]’) • Manipulation $(‘a[title][hash*=”foo”]’) • CSS $(‘a:first[hash*=”foo”]’) • Events $(‘.header, .footer’) • Effects • Ajax • Utilities
  • 81. Core $(‘#nav li.contact’) • Selectors $(‘:visible’) • Attributes $(‘:radio:enabled:checked’) • Traversing $(‘a[title]’) • Manipulation $(‘a[title][hash*=”foo”]’) • CSS $(‘a:first[hash*=”foo”]’) • Events $(‘.header, .footer’) • Effects $(‘.header, .footer’, ‘#main’) • Ajax • Utilities
  • 82. Insi de tip Performance getElementById getElementsByTagName getElementsByClassName querySelectorAll
  • 83. Insi de tip Performance ry s elec tors Que getElementById j fail s ilen tly, getElementsByTagName SS d oes! ju st l ike C getElementsByClassName querySelectorAll
  • 84. Core add() eq() • children() filter() Selectors closest() is() • Attributes contents() find() map() not() • Traversing next() nextAll() slice() • Manipulation offsetParent() parent() • CSS parents() prev() • Events prevAll() siblings() • Effects andSelf() • Ajax end() • Utilities
  • 85. Ne•wCore in add() eq() • .3 children() filter() Selectors 1 Attributes • closest() contents() is() map() find() not() • Traversing next() nextAll() slice() • Manipulation offsetParent() parent() • CSS parents() prev() • Events prevAll() siblings() • Effects andSelf() • Ajax end() • Utilities
  • 86. • Core add() eq() • Selectors children() filter() closest() is() • Searches down Attributes contents() find() map() not() • Traversing next() nextAll() slice() • Manipulation offsetParent() parent() • CSS parents() prev() • Events prevAll() siblings() • Effects andSelf() • Ajax end() • Utilities
  • 87. Core add() Filters across eq() • children() filter() Selectors closest() is() • Attributes contents() find() map() not() • Traversing next() nextAll() slice() • Manipulation offsetParent() parent() • CSS parents() prev() • Events prevAll() siblings() • Effects andSelf() • Ajax end() • Utilities
  • 88. Core add() eq() • children() filter() Selectors closest() is() • Attributes contents() find() map() not() • Traversing next() nextAll() slice() • Manipulation offsetParent() parent() • CSS parents() prev() • Events prevAll() siblings() • Effects andSelf() • Ajax end() • Utilities
  • 89. Core <!DOCTYPE html><html><body> • <ul> Selectors <li><a>one</a></li> • Attributes <li><a>two</a></li> <li><a>three</a></li> • Traversing </ul> <script src="jquery.js"> • Manipulation </script> <script> • CSS $('a').click(function () { alert( $(this) • Events .parent() .prevAll() • Effects ) .length • Ajax }); • </script> Utilities </body></html>http://jsbin.com/ubuhe/edit
  • 90. Core ready() blur() • change() Selectors bind() click() • Attributes one() trigger() dbclick() focus() • Traversing triggerHandler() keydown() unbind() keypress() • Manipulation live() keyup() mousedown() • CSS die() mousenter() mouseleave() • Events hover() toggle() mouseout() mouseup() • Effects load() resize() scroll() • Ajax unload() select() • error() submit() Utilities
  • 91. Core ready() blur() IE fires on blur • change() Selectors bind() click() • Attributes one() trigger() dbclick() focus() • Traversing triggerHandler() keydown() unbind() keypress() • Manipulation live() keyup() mousedown() • CSS die() mousenter() mouseleave() • Events hover() toggle() mouseout() mouseup() • Effects load() resize() scroll() • Ajax unload() select() • error() submit() Utilities
  • 92. Core ready() blur() • change() Selectors bind() click() • Attributes one() trigger() dbclick() focus() • Traversing triggerHandler() keydown() unbind() keypress() • Manipulation live() keyup() mousedown() • CSS die() mousenter() mouseleave() • Events hover() toggle() mouseout() mouseup() • Effects load() resize() scroll() • Ajax unload() select() • error() submit() Utilities
  • 93. Core <!DOCTYPE html> • <html> Selectors <body> • Attributes <p>1. click</p> • Traversing <p>2. click</p> • Manipulation <script src="jquery.js"></script> <script> • CSS $(‘p’).bind(‘click’, function(){ • Events $(this).after(‘<p>’ + ➥ $(this).text()+‘ clicked</p>’); • Effects }); • Ajax </script> </body> • Utilities </html> http://jsbin.com/ededi/edit
  • 94. Core <!DOCTYPE html> • <html> Selectors <body> • Attributes <p>1. click</p> • Traversing <p>2. click</p> • Manipulation <script src="jquery.js"></script> <script> • CSS $(‘p’).live(‘click’, function(){ • Events $(this).after(‘<p>’ + ➥ $(this).text()+‘ clicked</p>’); • Effects }); • Ajax </script> </body> • Utilities </html> http://jsbin.com/ihalu/edit
  • 95. Core $.fx.off • Selectors show() • Attributes hide() toggle() • Traversing slideDown() • Manipulation slideUp() • CSS slideToggle() • Events fadeIn() fadeOut() • Effects fadeTo() • Ajax animate() • Utilities stop()
  • 96. • Core control ew in Blanket FX $.fx.off N • Selectors show() 1.3 • Attributes hide() toggle() • Traversing slideDown() • Manipulation slideUp() • CSS slideToggle() • Events fadeIn() fadeOut() • Effects fadeTo() • Ajax animate() • Utilities stop()
  • 97. Core $.fx.off • Selectors show() • Attributes hide() toggle() • Traversing slideDown() • Manipulation slideUp() • CSS slideToggle() • Events fadeIn() fadeOut() • Effects fadeTo() • Ajax animate() • Utilities stop()
  • 98. Core <!DOCTYPE html><html><head> <style> • Selectors div {background:#bca; width:100px; border:1px solid green;} • Attributes </style> </head> • Traversing <body> <div id="block">Hello!</div> • Manipulation <script src="jquery.js"></script> <script> • CSS $(‘#block’).animate({ • Events ! width: ‘70%’, ! opacity: 0.4, • Effects ! marginLeft: ‘0.6in’, ! fontSize: ‘3em’, • Ajax ! borderWidth: ‘10px’ }, 1500); http://jsbin.com/oroto/edit • Utilities </script></body></html>
  • 99.
  • 100. Core $.ajax() ajaxCompete() • Selectors $.get() $.post() ajaxError() ajaxSend() • Attributes $.getJSON() $.getScript() ajaxStart() ajaxStop() • Traversing $.ajaxSetup() ajaxSuccess() • Manipulation load() • CSS serialize() • Events serializeArray() • Effects • Ajax • Utilities
  • 101. Core $.ajax() ajaxCompete() • Selectors $.get() $.post() ajaxError() ajaxSend() • Attributes $.getJSON() $.getScript() ajaxStart() ajaxStop() • Traversing $.ajaxSetup() ajaxSuccess() • Manipulation load() • CSS serialize() • Events serializeArray() • Effects • Ajax • Utilities
  • 102. Core <!DOCTYPE html><html><body> • <script src="jquery.js"> Selectors </script> • Attributes <script> • Traversing $.getJSON("http://twitter.com/ statuses/user_timeline.json? • Manipulation screen_name=rem&callback=?", function(data){ • CSS $.each(data,function(i,tweet){ $('<p/>').html • Events (tweet.text).appendTo('body'); if ( i == 30 ) return false; • Effects }); • }); Ajax </script></body></html> • Utilities http://jsbin.com/acisi/edit
  • 104. What’s a plugin? A plugin is nothing more than a custom jQuery method created to extend the functionality of the jQuery object $(‘ul’).myPlugin()
  • 105. Plugin design in 6 steps
  • 106. Step 1: create a private scope for $ alias
  • 108. Step 2: attach plugin to fn alias (aka prototype)
  • 109. <!DOCTYPE html><html><body> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }; // end of plugin })(jQuery); </script></body></html>
  • 110. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }; // end of plugin })(jQuery); $(‘p’).notHate(); </script></body></html>
  • 111. Step 3: add implicit iteration
  • 112. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { this.each(function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }); }; // end of plugin })(jQuery); $(‘p’).notHate(); </script></body></html>
  • 114. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }); }; // end of plugin })(jQuery); $(‘p’).notHate().hide(); </script></body></html>
  • 115. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> this == jQuery (function ($) { $.fn.notHate = function () { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }); }; // end of plugin })(jQuery); $(‘p’).notHate().hide(); </script></body></html>
  • 116. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> this == jQuery (function ($) { $.fn.notHate = function () { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ‘love’) ); }); }; // end of == DOM element this plugin })(jQuery); $(‘p’).notHate().hide(); </script></body></html>
  • 118. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ➥ $.fn.notHate.defaults.text) ); }); }; // end of plugin $.fn.notHate.defaults = {text:‘love’}; })(jQuery); $(‘p’).notHate(); </script></body></html>
  • 119. Step 6: add custom options
  • 120. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function () { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ➥ $.fn.notHate.defaults.text) ); }); }; // end of plugin $.fn.notHate.defaults = {text:‘love’}; })(jQuery); $(‘p’).notHate({text: ‘love-love-love’}); </script></body></html>
  • 121. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function (options) { return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ➥ $.fn.notHate.defaults.text) ); }); }; // end of plugin $.fn.notHate.defaults = {text:‘love’}; })(jQuery); $(‘p’).notHate({text: ‘love-love-love’}); </script></body></html>
  • 122. <!DOCTYPE html><html><body> <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function (options) { var settings = $.extend({}, ➥ $.fn.notHate.defaults, options); return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ➥ $.fn.notHate.defaults.text) ); }); }; // end of plugin $.fn.notHate.defaults = {text:‘love’}; })(jQuery); $(‘p’).notHate({text: ‘love-love-love’}); </script></body></html>
  • 123. <!DOCTYPE html><html><body> http://jsbin.com/ifuga/edit <p>I hate jQuery!</p> <p>I mean really hate jQuery!</p> <script src=”jquery.js”></script> <script> (function ($) { $.fn.notHate = function (options) { var settings = $.extend({}, ➥ $.fn.notHate.defaults, options); return this.each(function () { $(this).text( $(this).text().replace(/hate/g, ➥ settings.text) ); }); }; // end of plugin $.fn.notHate.defaults = {text:‘love’}; })(jQuery); $(‘p’).notHate({text: ‘love-love-love’}); </script></body></html>
  • 124.
  • 125. News • Four conferences next year: London, Boston, San Francisco and online • New plugin site • jQuery Forum (moving from Google Groups) • Mobile jQuery
  • 126. Demo!
  • 127. Remy Sharp @rem jQuery team member Co-author of O'Reilly jQuery Cookbook (due November 20th) jqueryfordesigners.com remysharp.com
  • 128. Remy Sharp @rem jQuery team member Co-author of O'Reilly jQuery Cookbook (due November 20th) jqueryfordesigners.com ? Questions remysharp.com