SlideShare a Scribd company logo
Introduc)on
for
Developers
Who
am
I?
• Jonathan
Sharp,
Omaha,
Nebraska
• Freelance
Developer
(Out
West
Media.com)
• jQuery
Team
member,
(web
&
infrastructure
team)
• Co‐authored
“jQuery
Cookbook”
(O’Reilly)
Q4
2009
• @jdsharp
Who
am
I?
• Own
a
horse
Overview
• Who,
what,
and
why
of
jQuery
• 5
core
jQuery
concepts
• Overview
of
jQuery
API
• Build
a
plugin
in
6
steps
• jQuery
Ini)a)ves
• Ques)ons
Who
uses
jQuery
• 35%
of
all
sites
that
use
JavaScript,
use
jQuery
• 1
out
5,
of
all
sites,
use
jQuery




                   h]p://trends.builtwith.com/javascript/JQuery
Who
uses
jQuery
• 35%
of
all
sites
that
use
JavaScript,
use
jQuery
• 1
out
5,
of
all
sites,
use
jQuery
     reddit.com
         whitehouse.gov
                            overstock.com
      espn.com
           wikipedia.org
                               )me.com
      ibm.com
           microsob.com
                              capitalone.com
 stackoverflow.com
        amazon.com
                                usatoday.com
    kickball.com
          netflix.com
                                 ning.com
      boxee.tv
             bing.com
                               wordpress.com
        bit.ly            monster.com
                                 dell.com
    twitpic.com              tv.com                                   twi]er.com

                     h]p://trends.builtwith.com/javascript/JQuery
Who
uses
jQuery
• 35%
of
all
sites
that
use
JavaScript,
use
jQuery
• 1
out
5,
of
all
sites,
use
jQuery
      reddit.com
        whitehouse.gov
                            overstock.com
       espn.com
          wikipedia.org
                               )me.com
       ibm.com
          microsob.com
                              capitalone.com
 stackoverflow.com
        amazon.com
                                usatoday.com
    kickball.com
          netflix.com
                                 ning.com
       boxee.tv
            bing.com
                               wordpress.com
         bit.ly           monster.com
                                 dell.com
     twitpic.com             tv.com                                   twi]er.com

                     h]p://trends.builtwith.com/javascript/JQuery
What
exactly
is
jQuery

jQuery
is
a
JavaScript
Library!

• Interac)on
with
the
DOM
 (e.g.
selec)ng,
crea)ng,
traversing,
changing
etc…)

• JavaScript
Events
• Anima)ons
• Ajax
interac)ons
What
does
that
mean?
Add
class
‘odd’
to
a
table
row...
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’;
        }
    }
};



                  ...becomes...
                h]p://jsbin.com/esewu/edit
Poetry

jQuery(‘table tr:nth-child(odd)’).addClass(‘odd’);
Using
jQuery
we
can
do
this

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




jQuery
func)on
Using
jQuery
we
can
do
this

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



                 jQuery
Selector
(CSS
Expression)

jQuery
func)on
Using
jQuery
we
can
do
this

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



                     jQuery
Selector
(CSS
Expression)

jQuery
func)on




        jQuery
Collec)on
Using
jQuery
we
can
do
this

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



                     jQuery
Selector
(CSS
Expression)

jQuery
func)on




        jQuery
Collec)on                            jQuery
Method
Using
jQuery
we
can
do
this

jQuery(‘table tr:nth-child(odd)’).addClass(‘odd’);
Further
Reduced

$(‘table tr:nth-child(odd)’).addClass(‘odd’);
Further
Reduced

var jQuery = function(...) { ... };

// $ is a valid variable character in JavaScript
var $ = jQuery;

$(‘table tr:nth-child(odd)’).addClass(‘odd’);
It
really
is
the


“write
less,
do
more”


 JavaScript
Library!
Why
use
jQuery
• Simplicity,
Speeds
up
web
development
• Avoids
common
headaches
w/
browsers
• Extensive
list
of
plugins
• Large
&
ac)ve
community
• Extensive
test
coverage
(50
browsers,
11
plahorms)
• API
for
both
coders
and
designers
Why
use
jQuery
over
other
soluNons
• Simplicity,
Speeds
up
web
development
• Avoids
common
headaches
w/
browsers
• Extensive
list
of
plugins
• Large
&
ac)ve
community
• Extensive
test
coverage
(50
browsers,
11
plahorms)
• API
for
both
coders
and
designers
Ok,
lets
get
to
it!
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul>
    
   <li><a>home</a></li>
    
   <li><a>about</a></li>
    </ul>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul>
    
   <li><a>home</a></li>
    
   <li><a>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’);
</script>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li><a>home</a></li>
    
   <li><a>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’).attr(‘id’,‘nav’);
</script>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li><a>home</a></li>
    
   <li><a>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘#nav li’);
</script>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a>home</a></li>
    
   <li class=‘navLiItem’><a>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘#nav li’).addClass(‘navLiItem’);
</script>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a>home</a></li>
    
   <li class=‘navLiItem’><a>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘#nav a’);
</script>
</body>
</html>
Concept
1.
Find
something,
do
something
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a href=‘/home’>home</a></li>
    
   <li class=‘navLiItem’><a href=‘/about’>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘#nav a’).each(function(){

   
   $(this).attr(‘href’,’/’ + $(this).text());

   });
</script>
</body>
</html>
Concept
2.
Create
something,
do
something
<!DOCTYPE html>
<html>
<body>
<ul id=‘nav’>
</ul>
</script>
</body>
</html>
Concept
2.
Create
something,
do
something
<!DOCTYPE html>
<html>
<body>
<ul id=‘nav’>
</ul>
<script src=‘jquery.js’></script>
<script>

   $(‘<li>home</li>’);
</script>
</body>
</html>
Concept
2.
Create
something,
do
something
<!DOCTYPE html>
<html>
<body>
<ul id=‘nav’>
</ul>
<script src=‘jquery.js’></script>
<script>

   $(‘<li>home</li>’).wrapInner(‘a’);
</script>
</body>
</html>
Concept
2.
Create
something,
do
something
<!DOCTYPE html>
<html>
<body>
<ul id=‘nav’>

   <li><a>home</a></li>

   <li><a>about</a></li>
</ul>
<script src=‘jquery.js’></script>
<script>

   $(‘<li>home</li>’).wrapInner(‘a’).appendTo(‘#nav’);

   $(‘<li>about</li>’).wrapInner(‘a’).appendTo(‘#nav’);
</script>
</body>
</html>
Concept
3.
Chaining
&
OperaNng
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a href=‘/home’>home</a></li>
    
   <li class=‘navLiItem’><a href=‘/about’>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’).attr(‘id’,’nav’);

   $(‘#nav li’).addClass(‘navLiItem’);

   $(‘#nav a’).each(function(){

   
   $(this).attr(‘href’,’/’ + $(this).text());

   });
</script>
</body>
</html>
Concept
3.
Chaining
&
OperaNng
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
    <li class=‘navLiItem’><a href=‘/home’>home</a></li>
    
    <li class=‘navLiItem’><a href=‘/about’>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’)

   
    .attr(‘id’,’nav’)

   
    .find(‘li’) // Push stack
   
     
   .addClass(‘navLiItem’)
       
     
   .find(‘a’) // Push stack
            
    
   .each(function(){
            
    
   
   $(this).attr(‘href’,’/’ + $(this).text());
            
    
   });
</script>
</body>
</html>
Concept
4.
Understanding
Implicit
iteraNon
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a href=‘/home’>home</a></li>
    
   <li class=‘navLiItem’><a href=‘/about’>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’)

   
   .attr(‘id’,’nav’)

   
   .find(‘li’)

   
   .addClass(‘navLiItem’)

   
   .find(‘a’)

   
   .each(function(){

   
   
   $(this).attr(‘href’,’/’ + $(this).text());

   
   });
</script>
</body>
</html>
Concept
4.
Understanding
Implicit
iteraNon
<!DOCTYPE html>
<html>
<body>
    <ul id=‘nav’>
    
   <li class=‘navLiItem’><a href=‘/home’>home</a></li>
    
   <li class=‘navLiItem’><a href=‘/about’>about</a></li>
    </ul>
<script src=‘jquery.js’></script>
<script>

   $(‘ul’)

   
   .attr(‘id’,’nav’)

   
   .find(‘li’)

   
   .addClass(‘navLiItem’)

   
   .find(‘a’)

   
   .each(function(){

   
   
   $(this).attr(‘href’,’/’ + $(this).text());

   
   });
</script>
</body>
</html>
Concept
5.
Knowing
the
jQuery
parameter
types


• CSS
Selectors
&
custom
CSS
expressions

 e.g. $(‘#nav’) and $(‘:first’)


• HTML

 e.g. $(‘<li><a href=“#”>link</a></li>’)


• DOM
Elements
 e.g. $(document) or $(document.createElement('a'))


• A
func)on
(shortcut
for
jQuery
DOM
ready
event)
 e.g. $(function(){}) = $(document).ready(function(){})
Review
• Find
something,
do
something
• Create
something,
do
something
• Chaining
&
Opera)ng
• Understanding
Implicit
Itera)on
• Knowing
the
jQuery
parameter
types
jQuery
API
overview
• Core
• Selectors
• A]ributes
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $()


• Selectors     each()
                size()

• A]ributes     length()
                selector()
                context()
• Traversing    eq()
                get()
• Manipula)on   index()


• CSS           data()
                removeData()
                queue()
• Events        dequeue()


• Effects        jQuery.fn.extend()
                jQuery.extend()

• Ajax          jQuery.noConflict()

• U)li)es
Overview
of
jQuery
API
• Core          $()


• Selectors     each()
                size()

• A]ributes     length()
                selector()
                context()
• Traversing    eq()
                get()
• Manipula)on   index()


• CSS           data()
                removeData()
                queue()
• Events        dequeue()


• Effects        jQuery.fn.extend()
                jQuery.extend()

• Ajax          jQuery.noConflict()

• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>


• A]ributes     <p>Element Node</p>

                <script src="http://ajax.googleapis.com/ajax/libs/
• Traversing    jquery/1.3.2/jquery.min.js" ></script>
                <script>
• Manipula)on   
    alert($(‘p’).get(0).nodeType);
                </script>

• CSS           </body>
                </html>
• Events
• Effects
• Ajax
• U)li)es                                 h]p://jsbin.com/aneki/edit#html
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>


• A]ributes     <p>Element Node</p>

                <script src="http://ajax.googleapis.com/ajax/libs/
• Traversing    jquery/1.3.2/jquery.min.js" ></script>
                <script>
• Manipula)on   
                
                     alert($(‘p’).get(0).nodeType);
                     alert($(‘p’)[0].nodeType);

• CSS           </script>

                </body>
• Events        </html>


• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core
• Selectors
• A]ributes
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors
• A]ributes
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)


• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing    $(‘a[title][href*=‘foo’]’)
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing    $(‘a[title][href*=‘foo’]’)
• Manipula)on   $(‘a:first[href*=‘foo’]’)

• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing    $(‘a[title][href*=‘foo’]’)
• Manipula)on   $(‘a:first[href*=‘foo’]’)

• CSS           $(‘#header,#footer’)

• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing    $(‘a[title][href*=‘foo’]’)
• Manipula)on   $(‘a:first[href*=‘foo’]’)

• CSS           $(‘#header,#footer’)

• Events        $(‘#mainContent,#sidebar’,’#content’)


• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $(‘#nav li.contact’)


• Selectors     $(‘:visible’)


• A]ributes     $(‘:radio:enabled:checked’)

                $(‘a[title]’)
• Traversing    $(‘a[title][href*=‘foo’]’)
• Manipula)on   $(‘a:first[href*=‘foo’]’)

• CSS           $(‘#header,#footer’)

• Events        $(‘#mainContent,#sidebar’,’#content’)


• Effects        h]p://codylindley.com/jqueryselectors/


• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          attr()
                removeAttr()
• Selectors
                addClass()
• A]ributes     hasClass()
                toggleClass()
• Traversing    removeClass()

• Manipula)on   val()

• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          attr()
                removeAttr()
• Selectors
                addClass()
• A]ributes     hasClass()
                toggleClass()
• Traversing    removeClass()

• Manipula)on   val()

• CSS
• Events
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html><html><body>


• Selectors     <input type="text" value="search" />

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

• A]ributes     <script>
                $('input')
                  .focus(function(){
• Traversing        var v = $(this).val();
                     $(this).val( v === this.defaultValue ? '' : v);

• Manipula)on
                  })
                  .blur(function(){
                    var v = $(this).val();

• CSS               $(this).val( v.match(/^s+$|^$/) ?

                  });
                       this.defaultValue : v);


• Events        </script></body></html>

• Effects
• Ajax
• U)li)es                                              h]p://jsbin.com/irico/edit#html
Overview
of
jQuery
API
• Core          add()            eq()
                children()       filter()
• Selectors     closest()        is()
                contents()       map()
• A]ributes     find()           not()
                next()           slice()
• Traversing    nextAll()
                offsetParent()
• Manipula)on   parent()
                parents()
• CSS           prev()
                prevAll()
• Events        siblings()

• Effects        andSelf()
                end()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          add()            eq()
                children()       filter()
• Selectors     closest()        is()
                contents()       map()
• A]ributes     find()           not()
                next()           slice()
• Traversing    nextAll()
                offsetParent()
• Manipula)on   parent()
                parents()
• CSS           prev()
                prevAll()
• Events        siblings()

• Effects        andSelf()
                end()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>


• A]ributes     <p>Make me bold!</p>

                <script src="http://ajax.googleapis.com/ajax/
• Traversing    libs/jquery/1.3.2/jquery.min.js" ></script>
                <script>
• Manipula)on   $(‘p’)

• CSS           
                
                     .contents()
                     .wrap(‘<strong></strong>’);

• Events        </script>
                </body>

• Effects        </html>


• Ajax
• U)li)es                                          h]p://jsbin.com/ituza/edit#html
Overview
of
jQuery
API
• Core          html()          replaceWith()
                text()          replaceAll()
• Selectors
                append()        empty()
• A]ributes     appendTo()      remove()
                prepend()
• Traversing    prependTo()     clone()

• Manipula)on   after()
                before()
• CSS           insert()
                insertAfter()
• Events        insertBefore

• Effects        warp()
                wrapAll()
• Ajax          wrapInner()

• U)li)es
Overview
of
jQuery
API
• Core          html()          replaceWith()
                text()          replaceAll()
• Selectors
                append()        empty()
• A]ributes     appendTo()      remove()
                prepend()
• Traversing    prependTo()     clone()

• Manipula)on   after()
                before()
• CSS           insert()
                insertAfter()
• Events        insertBefore

• Effects        warp()
                wrapAll()
• Ajax          wrapInner()

• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>

• A]ributes     <p>jQuery</p>

• Traversing    <script src="jquery.js"></script>
                <script>
• Manipula)on
                alert($(‘p’).text());
• CSS
                </script>
• Events        </body>
                </html>
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          css()

• Selectors     offset()
                offsetParent()
• A]ributes     position()
                scrollTop()
• Traversing    scrollLeft()

• Manipula)on   height()
                width()
• CSS           innerHeight()
                innerWidth()
• Events        outerHeight()
                outerWidth()
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          css()

• Selectors     offset()
                offsetParent()
• A]ributes     position()
                scrollTop()
• Traversing    scrollLeft()

• Manipula)on   height()
                width()
• CSS           innerHeight()
                innerWidth()
• Events        outerHeight()
                outerWidth()
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <head>
                <style>div{background-color:#ccc; width:100px;

• A]ributes     margin:0 20px; float:left;}</style>
                </head>
                <body>
• Traversing    <div></div>
• Manipula)on   <div></div>
                <div></div>

• CSS           <script src=“jquery.js" ></script>
                <script>
• Events        $('div')

• Effects        
    .height($(document).height());


• Ajax
                </script>
                </body>
                </html>
• U)li)es
Overview
of
jQuery
API
• Core          ready()            blur()
                                   change()
• Selectors     bind()
                one()
                                   click()
                                   dbclick()

• A]ributes     trigger()
                triggerHandler()
                                   error()
                                   focus()
                unbind()           keydown()
• Traversing    live()
                                   keypress()
                                   keyup()
• Manipula)on   die()              mousedown()
                                   mousenter()

• CSS           hover()
                toggle()
                                   mouseleave()
                                   mouseout()
                                   mouseup()
• Events                           resize()
                                   scroll()

• Effects                           select()
                                   submit()

• Ajax
                                   unload()



• U)li)es
Overview
of
jQuery
API
• Core          ready()            blur()
                                   change()
• Selectors     bind()
                one()
                                   click()
                                   dbclick()

• A]ributes     trigger()
                triggerHandler()
                                   error()
                                   focus()
                unbind()           keydown()
• Traversing    live()
                                   keypress()
                                   keyup()
• Manipula)on   die()              mousedown()
                                   mousenter()

• CSS           hover()
                toggle()
                                   mouseleave()
                                   mouseout()
                                   mouseup()
• Events                           resize()
                                   scroll()

• Effects                           select()
                                   submit()

• Ajax
                                   unload()



• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>

• A]ributes     <p>click me</p>
                <p>click me</p>
• Traversing    <script src="jquery.js"></script>

• Manipula)on   <script>


• CSS
                $("p").bind("click", function(){
                      $(this).after("<p>click me</p>");
                });
• Events
                </script>
• Effects        </body>
                </html>
• Ajax
• U)li)es                                 h]p://jsbin.com/ehuki/edit#html
Overview
of
jQuery
API
• Core          <!DOCTYPE html>
                <html>
• Selectors     <body>

• A]ributes     <p>click me</p>
                <p>click me</p>
• Traversing    <script src="jquery.js"></script>

• Manipula)on   <script>


• CSS
                $("p").live("click", function(){
                      $(this).after("<p>click me</p>");
                });
• Events
                </script>
• Effects        </body>
                </html>
• Ajax
• U)li)es                                 h]p://jsbin.com/epeha/edit#html
Overview
of
jQuery
API
• Core          show()
                hide()
• Selectors     toggle()

• A]ributes     slideDown()
                slideUp()
• Traversing    slideToggle()

• Manipula)on   fadeIn()
                fadeOut()
• CSS           fadeTo()

• Events        animate()
                stop()
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          show()
                hide()
• Selectors     toggle()

• A]ributes     slideDown()
                slideUp()
• Traversing    slideToggle()

• Manipula)on   fadeIn()
                fadeOut()
• CSS           fadeTo()

• Events        animate()
                stop()
• Effects
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE html><html><head>
                <style>
• Selectors     div{background-color:#bca;width:100px;border:1px
                solid green;}

• A]ributes     </style>
                </head>
                <body>
• Traversing    <div id="block">Hello!</div>
                <script src="http://ajax.googleapis.com/ajax/
• Manipula)on   libs/jquery/1.3.2/jquery.min.js" ></script>
                <script>

• CSS           $("#block").animate({
                
    width: ‘70%’,
• Events        
                
                     opacity: 0.4,
                     marginLeft: ‘0.6in’,

• Effects        
                
                     fontSize: ‘3em’,
                     borderWidth: ‘10px’

• Ajax
                }, 1500);

                </script></body></html>
• U)li)es                                     h]p://jsbin.com/evage/edit#html
Overview
of
jQuery
API
• Core          jQuery.ajax()         jQuery.ajaxSetup()

                jQuery.get()          serialize()
• Selectors     jQuery.getJSON()
     serializeArray()
• A]ributes     jQuery.getScript()

                jQuery.post()
• Traversing    load()
• Manipula)on
                ajaxCompete()
• CSS           ajaxError()
                ajaxSend()
• Events        ajaxStart()
• Effects        ajaxStop()
                ajaxSuccess()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          jQuery.ajax()         jQuery.ajaxSetup()

                jQuery.get()          serialize()
• Selectors     jQuery.getJSON()
     serializeArray()
• A]ributes     jQuery,getScript()

                jQuery.post()
• Traversing    load()
• Manipula)on
                ajaxCompete()
• CSS           ajaxError()
                ajaxSend()
• Events        ajaxStart()
• Effects        ajaxStop()
                ajaxSuccess()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          <!DOCTYPE
html><html><body>

                <script
src="h]p://ajax.googleapis.com/ajax/libs/jquery/
• Selectors     1.3.2/jquery.min.js"
></script>

                <script>


• A]ributes     var
url
=
‘h]p://api.flickr.com/services/feeds/
                photos_public.gne?
• Traversing    tags=jquery&tagmode=all&format=json&jsoncallback=?’;

• Manipula)on   $.getJSON(url,
func)on(data){

• CSS           



$.each(data.items,
func)on(i,item){

                







$("<img/>")
• Events        
         .a]r("src",
item.media.m).appendTo("body");

                







if
(
i
==
30
)
return
false;

• Effects        



});

                });

• Ajax          </script>
</body></html>

• U)li)es                                             h]p://jsbin.com/erase/edit#html
Overview
of
jQuery
API
• Core          $.support         $.trim()
                $.boxModel
• Selectors                       $.param()
• A]ributes     $.each(),

                $.extend(),

• Traversing    $.grep(),

                $.makeArray(),

• Manipula)on   $.map(),

                $.inArray(),

• CSS           $.merge(),

                $.unique()
• Events
• Effects        $.isArray(),

                $,isFunc)on()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $.support         $.trim()
                $.boxModel
• Selectors                       $.param()
• A]ributes     $.each(),

                $.extend(),

• Traversing    $.grep(),

                $.makeArray(),

• Manipula)on   $.map(),

                $.inArray(),

• CSS           $.merge(),

                $.unique()
• Events
• Effects        $.isArray(),

                $,isFunc)on()
• Ajax
• U)li)es
Overview
of
jQuery
API
• Core          $.each(data.items, function(i,item){


• Selectors     $("<img/>")
                
    .attr("src”,item.media.m).appendTo("body");


• A]ributes     if ( i == 30 ) return false;

                });
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
What
happen
to
the
$
alias
and
the
$
    (document).ready()
event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{

   //jQuery code here
})
</script>
</head>
<body>
</script>
</body>
</html>
What
happen
to
the
$
alias
and
the
$
    (document).ready()
event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{

   alert($(document).jquery);
})
</script>
</head>
<body>
</script>
</body>
</html>
What
happen
to
the
$
alias
and
the
$
    (document).ready()
event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{

   alert($(document).jquery);
})
</script>
</head>
<body>
</script>
</body>
</html>
What
happen
to
the
$
alias
and
the
$
    (document).ready()
event
<!DOCTYPE html>
<html>
<body>
<script src=“jquery.js”></script>
<script>
alert($(document).jquery);
</script>
</body>
</html>
What
happen
to
the
$
alias
and
the
$
    (document).ready()
event
<!DOCTYPE html>
<html>
<body>
<script src=“jquery.js”></script>
<script>
alert($(document).jquery);
(function($){

   alert($().jquery);
})(jQuery);
</script>
</body>
</html>
Plugins!
So,
what
is
a
plugin?
A
plugin
is
nothing
more
than
a
custom
jQuery

method
created
to
extend
the
func)onality
of

the
jQuery
object

                $(‘ul’).myPlugin()
Why
Create
a
plugin?
You
want
to
“find
something”,
and
“do

something”
but
the
“do
something”
is
not

available
in
jQuery.


Roll
your
own
“do
something”
with
a
plugin!
A
jQuery
plugin
in
6
steps



      h]p://jsbin.com/eheku/edit
A
jQuery
plugin
in
6
steps
Step
1.
create
a
private
scope
for
$
alias
<!DOCTYPE html><html><body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){

})(jQuery);
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
2.
a]ach
plugin
to
fn
alias
(aka
prototype)
<!DOCTYPE html><html><body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
    
   $(this).text($(this).text().replace(/hate/g,'love'));
    };
})(jQuery);
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
2.
a]ach
plugin
to
fn
alias
(aka
prototype)
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
    
   $(this).text($(this).text().replace(/hate/g,'love'));
    };
})(jQuery);
$('p').loveNotHate();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
3.
add
implicit
itera)on
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        this.each(function(){
 
   
            $(this).text($(this).text().replace(/hate/g,'love'));
        });
    };
})(jQuery);
$('p').loveNotHate();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
3.
add
implicit
itera)on
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        this.each(function(){
 
   
            $(this).text($(this).text().replace(/hate/g,'love'));
        });
    };
})(jQuery);
$('p').loveNotHate();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
4.
enable
chaining
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,'love'));
        });
    };
})(jQuery);
$('p').loveNotHate();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
4.
enable
chaining
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,'love'));
        });
    };
})(jQuery);
$('p').loveNotHate().hide();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
5.
add
default
op)ons
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,
            $.fn.loveNotHate.defaultOptions.text));
        });
    };
    $.fn.loveNotHate.defaultOptions = {text:'love'};
})(jQuery);
$('p').loveNotHate();
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
6.
add
custom
op)ons
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(){
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,
            $.fn.loveNotHate.defaultOptions.text));
        });
    };
    $.fn.loveNotHate.defaultOptions = {text:'love'};
})(jQuery);
$('p').loveNotHate({text:'love-love-love'});
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
6.
add
custom
op)ons
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(customOptions){
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,
            $.fn.loveNotHate.defaultOptions.text));
        });
    };
    $.fn.loveNotHate.defaultOptions = {text:'love'};
})(jQuery);
$('p').loveNotHate({text:'love-love-love'});
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
6.
add
custom
op)ons
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(customOptions){
        var options = $.extend({},$.fn.loveNotHate.defaultOptions,
        customOptions);
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/g,
            $.fn.loveNotHate.defaultOptions.text));
        });
    };
    $.fn.loveNotHate.defaultOptions = {text:'love'};
})(jQuery);
$('p').loveNotHate({text:'love-love-love'});
</script></body></html>
A
jQuery
plugin
in
6
steps
Step
6.
add
custom
op)ons
<!DOCTYPE html><html><body>
<p>I hate jQuery!</p>
<p>I mean really hate jQuery!</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.min.js"></script>
<script>
(function($){
    $.fn.loveNotHate = function(customOptions){
        var options = $.extend({},$.fn.loveNotHate.defaultOptions,
        customOptions);
        return this.each(function(){
 
    
            $(this).text($(this).text().replace(/hate/
            g,options.text));
        });
    };
    $.fn.loveNotHate.defaultOptions = {text:'love'};
})(jQuery);
$('p').loveNotHate({text:'love-love-love'});
</script></body></html>
Plugins
are
simple,
just
follow
the
steps!
jQuery
News
• jQuery.org
&
Founda)on
(Sobware
Freedom
Law

  Center)
• Tax‐deduc)ble
dona)ons
• Four
conferences
next
year
(Boston,
San
Francisco,

  London,
and
online)
• Infrastructure
Upgrade
(MediaTemple
Sponsorship)
• New
Plugin
site
(h]p://plugins.jquery.com)
• jQuery
Forum
(moving
away
from
Google
Groups)
?
Jonathan
Sharp
(@jdsharp)

 Special
thanks
to
Cody
Lindley

More Related Content

PDF
jQuery Essentials
PPTX
Unobtrusive javascript with jQuery
PDF
jQuery Features to Avoid
PDF
jQuery Loves Developers - Oredev 2009
PDF
jQuery for beginners
PPTX
SharePoint and jQuery Essentials
PDF
Write Less Do More
PDF
jQuery Essentials
jQuery Essentials
Unobtrusive javascript with jQuery
jQuery Features to Avoid
jQuery Loves Developers - Oredev 2009
jQuery for beginners
SharePoint and jQuery Essentials
Write Less Do More
jQuery Essentials

What's hot (20)

PPTX
jQuery Presentation
PDF
jQuery Basic API
PPTX
jQuery quick tuts
ODP
Introduction to jQuery
PDF
Learning jQuery made exciting in an interactive session by one of our team me...
PPT
PPTX
PDF
jQuery: Nuts, Bolts and Bling
PPTX
jQuery Fundamentals
PPTX
Jquery-overview
PPTX
Getting the Most Out of jQuery Widgets
PPT
JQuery introduction
PPTX
Introduction to jQuery
ODP
Drupal Best Practices
PPTX
jQuery from the very beginning
PPTX
FuncUnit
KEY
jQuery('#knowledge').appendTo('#you');
PDF
Prototype & jQuery
PDF
Learning jQuery in 30 minutes
jQuery Presentation
jQuery Basic API
jQuery quick tuts
Introduction to jQuery
Learning jQuery made exciting in an interactive session by one of our team me...
jQuery: Nuts, Bolts and Bling
jQuery Fundamentals
Jquery-overview
Getting the Most Out of jQuery Widgets
JQuery introduction
Introduction to jQuery
Drupal Best Practices
jQuery from the very beginning
FuncUnit
jQuery('#knowledge').appendTo('#you');
Prototype & jQuery
Learning jQuery in 30 minutes
Ad

Similar to Stack Overflow Austin - jQuery for Developers (20)

PDF
Devdays Seattle jQuery Intro for Developers
PPTX
Jquery fundamentals
KEY
Week 4 - jQuery + Ajax
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
PDF
Yearning jQuery
PPTX
Upstate CSCI 450 jQuery
PPT
J query b_dotnet_ug_meet_12_may_2012
PDF
fuser interface-development-using-jquery
PPT
jQuery Introduction/ jquery basic concept
PPT
J query presentation
PPT
J query presentation
PDF
jQuery Introduction
PDF
What's this jQuery? Where it came from, and how it will drive innovation
PDF
Cleaner, Leaner, Meaner: Refactoring your jQuery
PPT
jQuery For Beginners - jQuery Conference 2009
PDF
Remy Sharp The DOM scripting toolkit jQuery
PPTX
Jqueryppt (1)
PDF
J query fundamentals
PDF
Jquery Cookbook Solutions Examples For Jquery Developers Lindley
PDF
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Devdays Seattle jQuery Intro for Developers
Jquery fundamentals
Week 4 - jQuery + Ajax
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Yearning jQuery
Upstate CSCI 450 jQuery
J query b_dotnet_ug_meet_12_may_2012
fuser interface-development-using-jquery
jQuery Introduction/ jquery basic concept
J query presentation
J query presentation
jQuery Introduction
What's this jQuery? Where it came from, and how it will drive innovation
Cleaner, Leaner, Meaner: Refactoring your jQuery
jQuery For Beginners - jQuery Conference 2009
Remy Sharp The DOM scripting toolkit jQuery
Jqueryppt (1)
J query fundamentals
Jquery Cookbook Solutions Examples For Jquery Developers Lindley
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PPT
Teaching material agriculture food technology
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Teaching material agriculture food technology
GamePlan Trading System Review: Professional Trader's Honest Take
20250228 LYD VKU AI Blended-Learning.pptx
madgavkar20181017ppt McKinsey Presentation.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Review of recent advances in non-invasive hemoglobin estimation
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Advanced methodologies resolving dimensionality complications for autism neur...

Stack Overflow Austin - jQuery for Developers