SlideShare a Scribd company logo
jQuery
 Basic APIs




              http://hyeonseok.com
http://jquery.com
jQuery
introduction




               http://hyeonseok.com
Introduction
JavaScript library
๏            UI                                            .

    -                                                  .

๏
                   .

    -   Prototype, mooTools, YUI, Dojo, Ext JS, etc.

๏                                                              .

    -                                                              .

    -          (       ,   ,       )               .



                                                                       http://hyeonseok.com
Introduction
jQuery write less, do more
๏                     .

๏                 .

๏                         .

๏                                     .

๏                             .

๏                                 .

๏ MIT and GPL licenses.



                                          http://hyeonseok.com
Introduction
Installation
๏ jquery.com                                                                            .
    <script src="jquery.js"></script>
    <script>
    // your script goes here.
    </script>



๏ CDN(Content delivery network)                                      .

   -   Google Ajax API CDN: http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js

   -   Microsoft CDN: http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js

   -   jQuery CDN: http://code.jquery.com/jquery-1.6.1.min.js




                                                                                            http://hyeonseok.com
http://www.panic.com/coda/
jQuery
  core




         http://hyeonseok.com
Core
jQuery()
๏ jQuery( selector, [ context ] )
   -   $()                            .

   -   CSS                                          jQuery   .

   -   Selector Context

       -                                                .

             $('div.foo').click(function() {
                 $('span', this).addClass('bar');
             });




                                                             http://hyeonseok.com
Core
jQuery()
๏ jQuery( element ), jQuery( elementArray )
  -   DOM                               .

      -   this        jQuery                         .

           $('div.foo').click(function() {
               $(this).slideUp();
           });


      -   AJAX          XML       $                      .

           $.post('url.xml', function(data) {
               var $child = $(data).find('child');
           })




                                                             http://hyeonseok.com
Core
jQuery()
๏ jQuery( jQuery object )
  -   jQuery                      jQuery       .

๏ jQuery()

  -                 .length   0            .




                                                   http://hyeonseok.com
Core
jQuery()
๏ jQuery( html, [ ownerDocument ] )
  -   HTML                                        .

  -                       jQuery      createElement
      innerHTML                           .

  -   html, title, head                               .

  -             HTML
                .




                                                          http://hyeonseok.com
Core
jQuery()
๏ jQuery( html, props )
  -                                          .
      $("<div/>", {
          "class": "test",
          text: "Click me!",
          click: function(){
              $(this).toggleClass("test");
          }
      }).appendTo("body");




                                                 http://hyeonseok.com
Core
jQuery()
๏ jQuery( callback )
  -   $(document).ready()         DOM
                         .
       $(function(){
           // Document is ready
       });




                                        http://hyeonseok.com
Core
๏ jQuery.holdReady()
  -   Holds or releases the execution of jQuery's ready event.

๏ jQuery.noConflict()
  -   Relinquish jQuery's control of the $ variable.

๏ jQuery.sub()
  -   Creates a new copy of jQuery whose properties and methods can be
      modified without affecting the original jQuery object.

๏ jQuery.when()
  -   Provides a way to execute callback functions based on one or more
      objects, usually Deferred objects that represent asynchronous events.



                                                                              http://hyeonseok.com
Core
Chaining
๏              jQuery               jQuery      .

    -                                       .

    $('div.section').hide().addClass('gone');


๏                          .end()
           .
    $('ul.first').find('.foo')
        .css('background-color', 'red')
    .end().find('.bar')
        .css('background-color', 'green')
    .end();




                                                    http://hyeonseok.com
jQuery
 selectors




             http://hyeonseok.com
Selectors
Basic
๏ CSS                                       .

  -   All Selector ("*")

  -   Class Selector (".class")

  -   Element Selector ("element")

  -   ID Selector ("#id")

  -   Multiple Selector ("selector1, selector2, selectorN")




                                                              http://hyeonseok.com
Selectors
Attribute
๏ Has Attribute Selector [name]

๏ Attribute Equals Selector [name="value"]

๏ Attribute Not Equal Selector [name!="value"]

๏ Attribute Starts With Selector [name^="value"]

๏ Attribute Ends With Selector [name$="value"]




                                                   http://hyeonseok.com
Selectors
Attribute
๏ Multiple Attribute Selector [name="value"][name2="value2"]

๏ Attribute Contains Selector [name*="value"]

๏ Attribute Contains Prefix Selector [name|="value"]

๏ Attribute Contains Word Selector [name~="value"]




                                                           http://hyeonseok.com
Selectors
Basic Filter
๏ :first Selector, :last Selector
   -                     ,             .

๏ :even Selector, :odd Selector

   -      ,                        .




                                           http://hyeonseok.com
Selectors
Basic Filter
๏ :eq() Selector
   -   n                      .

       <table border="1">
           <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>
           <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>
           <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
       </table>
       <script>$("td:eq(2)").css("color", "red");</script>




                                                                 http://hyeonseok.com
Selectors
Basic Filter
๏ :lt() Selector, :gt() Selector
   -   n          ,n                          .

       <table border="1">
           <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>
           <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>
           <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
       </table>
       <script>$("td:lt(4)").css("color", "red");</script>




                                                                 http://hyeonseok.com
Selectors
Basic Filter
๏ :header Selector
   -                   .

๏ :not() Selector

   -                           .

๏ :animated Selector
   -                       .




                                   http://hyeonseok.com
Selectors
Child Filter
๏ :first-child Selector, :last-child Selector
   -                  ,                        .

๏ :only-child Selector

   -                             .




                                                   http://hyeonseok.com
Selectors
Child Filter
๏ :nth-child() Selector
   -               n                            .

       <ul>
            <li>John</li>
            <li>Karl</li>
            <li>Brandon</li>
       </ul>
       <ul>
            <li>Sam</li>
       </ul>
       <ul>
            <li>Glen</li>
            <li>Tane</li>
            <li>Ralph</li>
            <li>David</li>
       </ul>
       <script>$("ul li:nth-child(2)").append("<span> - 2nd!</span>");</
       script>




                                                                           http://hyeonseok.com
Selectors
Content Filter
๏ :contains() Selector
   -                                            .

       <div>John Resig</div>
       <div>George Martin</div>
       <div>Malcom John Sinclair</div>
       <div>J. Ohn</div>
       <script>
       $("div:contains('John')").css("text-decoration", "underline");
       </script>




                                                                        http://hyeonseok.com
Selectors
Content Filter
๏ :empty Selector
   -                 .

๏ :parent Selector

   -                     .

๏ :has() Selector
   -                         .




                                 http://hyeonseok.com
Selectors
Form
๏ :input Selector, :checkbox Selector, :radio Selector

๏ :text Selector, :password Selector, :file Selector

๏ :button Selector, :submit Selector, :image Selector, :reset
  Selector

๏ :focus selector

๏ :checked Selector

๏ :selected Selector

๏ :enabled Selector, :disabled Selector


                                                                http://hyeonseok.com
Selectors
Hierarchy
๏ Child Selector ("parent > child")
   -                              .

๏ Descendant Selector ("ancestor descendant")

   -                          .

๏ Next Adjacent Selector ("prev + next")
   -   prev            next                .




                                                http://hyeonseok.com
Selectors
Hierarchy
๏ Next Siblings Selector ("prev ~ siblings")
   -   prev                                        .

       <div>div (doesn't match since before #prev)</div>
       <span id="prev">span#prev</span>
       <div>div sibling</div>
       <div>div sibling <div id="small">div niece</div></div>
       <span>span sibling (not div)</span>
       <div>div sibling</div>
       <script>$("#prev ~ div").css("border", "3px groove blue");</script>




                                                                         http://hyeonseok.com
Selectors
Visibility Filter
๏ :visible Selector
   -                  .

๏ :hidden Selector

   -                      .




                              http://hyeonseok.com
jQuery
 traversing




              http://hyeonseok.com
Traversing
Tree Traversal
๏ .children()
   -                     .                                 .

       <p>Hello (this is a paragraph)</p>
       <div><span>Hello Again (this span is a child of the a div)</span></
       div>
       <p>And <span>Again</span> (in another paragraph)</p>
       <div>And One Last <span>Time</span> (most text directly in a div)</
       div>
       <script>
       $("div").children().css("border-bottom", "3px double red");
       </script>




                                                                         http://hyeonseok.com
Traversing
Tree Traversal
๏ .siblings()
   -                      .

       <div><span>Hello</span></div>
       <p class="selected">Hello Again</p>
       <p>And Again</p>
       <script>
       $("p").siblings(".selected").css("background", "yellow");
       </script>




                                                                   http://hyeonseok.com
Traversing
Tree Traversal
๏ .closest()
   -
        .

๏ .find()
   -                         , jQuery     , DOM
                .
       <p><span>Hello</span>, how are you?</p>
       <p>Me? I'm <span>good</span>.</p>
       <div>Did you <span>eat</span> yet?</div>
       <script>
       var $spans = $('span');
       $("p").find( $spans ).css('color','red');
       </script>




                                                   http://hyeonseok.com
Traversing
Tree Traversal
๏ .next()
   -             .

๏ .nextAll()

   -                 .

๏ .nextUntil()
   -                     .




                             http://hyeonseok.com
Traversing
Tree Traversal
๏ .prev()
   -             .

๏ .prevAll()

   -                 .

๏ .prevUntil()
   -                     .




                             http://hyeonseok.com
Traversing
Tree Traversal
๏ .parent()
   -                .

๏ .parents()

   -                    .

๏ .parentsUntil()
   -                            .

๏ .offsetParent()

   -                        .


                                    http://hyeonseok.com
Traversing
Filtering
๏ .eq()
   -   n     .

๏ .first()

   -         .

๏ .last()
   -         .

๏ .slice()

   -             .


                     http://hyeonseok.com
Traversing
Filtering
๏ .has()
   -                    DOM
              .

๏ .not()
   -              .

๏ .is()

   -                  , jQuery
          .




                                 http://hyeonseok.com
Traversing
Filtering
๏ .map()
   -                            jQuery
             .

๏ .filter()
   -             , jQuery   ,            .




                                             http://hyeonseok.com
Traversing
Miscellaneous Traversing
๏ .add()
  -                         jQuery                  .

๏ .end()

  -                                                               .
      <p><span>Hello</span>, how are you?</p>
      <script>
      $("p").find("span").end().css("border", "2px red solid");
      </script>




                                                                      http://hyeonseok.com
Traversing
Miscellaneous Traversing
๏ .contents()
  -                                          . .children()
        .contents()                                  .
      <div class="container">
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna
      aliqua.</p>
          <br /><br />
          <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
      laboris nisi ut aliquip ex ea commodo consequat.</p>
          <br /><br />
          <p>Duis aute irure dolor in reprehenderit in voluptate velit
      esse cillum dolore eu fugiat nulla pariatur.</p>
      </div>
      <script>
      $('.container').contents().filter(function() {
          return this.nodeType == 3;
      }).wrap('<p></p>').end().filter('br').remove();
      </script>



                                                                          http://hyeonseok.com
Traversing
Miscellaneous Traversing
๏ .andSelf()
  -                                          .
      <div>
          <p>First Paragraph</p>
          <p>Second Paragraph</p>
      </div>
      <script>
          $("div").find("p").andSelf().addClass("border");
      </script>




                                                             http://hyeonseok.com
jQuery
manipulation




               http://hyeonseok.com
Manipulation
General Attributes
๏ .attr()
   -   HTML                           ,          .

       $('#greatphoto').attr('alt', 'Beijing Brush Seller');


   -   JSON                                                    .

       $('#greatphoto').attr({
           alt: 'Beijing Brush Seller',
           title: 'photo by Kelly Clark'
       });


๏ .removeAttr()
   -   HTML                 .



                                                                   http://hyeonseok.com
Manipulation
General Attributes
๏ .prop()
  -                                                      ,        .

  -   <input type="checkbox" checked="checked" />                     (jQuery 1.6    )


      -   $('input').attr('checked') == 'checked' (string type)

      -   $('input').prop('checked') == true (boolean type)


๏ .removeProp()
  -                                        .




                                                                                    http://hyeonseok.com
Manipulation
General Attributes
๏ .val()
   -       (value)       .

       $('input:text.items').val(function(index, value) {
           return value + ' ' + this.className;
       });




                                                            http://hyeonseok.com
Manipulation
Class Attribute
๏ .addClass()
  -         (class)           .

๏ .removeClass()

  -                                          .

      $("p").removeClass("myClass noClass").addClass("yourClass");


๏ .hasClass()
  -                                              .

      var hasFoo = $('p').hasClass('foo');




                                                                     http://hyeonseok.com
Manipulation
Class Attribute
๏ .toggleClass()
   -                                             .
       <p class="blue">Click to toggle</p>
       <p class="blue highlight">highlight</p>
       <p class="blue">on these</p>
       <p class="blue">paragraphs</p>
       <script>
       $("p").click(function () {
           $(this).toggleClass("highlight");
       });
       </script>




                                                     http://hyeonseok.com
Manipulation
DOM Insertion, Inside
๏ .text()
   -                                  ,          .

       $('div.demo-container').text('<p>This is a test.</p>');


๏ .html()

   -   HTML                           ,         .

       $('div.demo-container').html('<p>All new content. <em>You bet!</
       em></p>');




                                                                          http://hyeonseok.com
Manipulation
DOM Insertion, Inside
๏ .prepend()
  -            jQuery   .

๏ .prependTo()

  -   jQuery            .




                            http://hyeonseok.com
Manipulation
DOM Insertion, Inside
๏ .append()
  -            jQuery   .

๏ .appendTo()

  -   jQuery            .




                            http://hyeonseok.com
Manipulation
DOM Insertion, Outside
๏ .before()
   -            jQuery   .

๏ .insertBefore()

   -   jQuery            .




                             http://hyeonseok.com
Manipulation
DOM Insertion, Outside
๏ .after()
   -            jQuery   .

๏ .insertAfter()

   -   jQuery            .




                             http://hyeonseok.com
Manipulation
DOM Removal
๏ .remove()
  -   DOM      .

๏ .detach()

  -   DOM      .
                   .

๏ .empty()

  -   DOM              .




                           http://hyeonseok.com
Manipulation
DOM Replacement
๏ .replaceWith()
   -                 jQuery                   .

       <buttondiv>First</buttondiv>
       <buttondiv>Second</buttondiv>
       <buttondiv>Third</buttondiv>

       <script>
       $("button").click(function () {
           $(this).replaceWith( "<div>" + $(this).text() + "</div>" );
       });
       </script>


๏ .replaceAll()

   -   jQuery                                 .



                                                                         http://hyeonseok.com
Manipulation
DOM Insertion, Around
๏ .wrap()
  -                           .

      <div><p>Hello</p></div>
      <div><p>cruel</p></div>
      <div><p>World</p></div>
      <script>$("p").wrap("<div></div>");</script>


๏ .wrapAll()

  -                                  .

      <div><p>Hello</p>
      <p>cruel</p>
      <p>World</p></div>
      <script>$("p").wrapAll("<div></div>");</script>




                                                        http://hyeonseok.com
Manipulation
DOM Insertion, Around
๏ .unwrap()
  -                                     .

๏ .wrapInner()

  -                                            .
      <p><b>Hello</b></p>
      <p><b>cruel</b></p>
      <p><b>World</b></p>
      <script>$("p").wrapInner("<b></b>");</script>




                                                      http://hyeonseok.com
Manipulation
Copying
๏ .clone()
  -                   .

      <b>Hello</b><p><b>Hello</b>, how are you?</p>

      <script>
          $("b").clone().prependTo("p");
      </script>




                                                      http://hyeonseok.com
Manipulation
Style Properties
๏ .css()
   -                                            ,        .

   -                                                .

       $('#mydiv').css('color', 'green');


   -   index                                .
       $('div.example').css('width', function(index) {
           return index * 50;
       });




                                                             http://hyeonseok.com
Manipulation
Style Properties
๏ .height()
   -                                       .

       var height = $('div#intro').height();


๏ .innerHeight()

   -                                           .

๏ .outerHeight()
   -       ,                                       .

   -                                   .



                                                       http://hyeonseok.com
Manipulation
Style Properties
๏ .width()
  -                .

๏ .innerWidth()

  -                    .

๏ .outerWidth()
  -      ,                 .




                               http://hyeonseok.com
Manipulation
Style Properties
๏ .position()
   -                   .

๏ .offset()

   -               .




                           http://hyeonseok.com
Manipulation
Style Properties
๏ .scrollLeft()
   -               .

๏ .scrollTop()

   -               .




                       http://hyeonseok.com
jQuery
  event




          http://hyeonseok.com
Event
Event handling
๏                                                   .
    $('a:first').click(function(ev) {
        $(this).css({backgroundColor: 'orange'});
        return false; // Or ev.preventDefault();
    });
    $('a:first').click();




                                                        http://hyeonseok.com
Event
Keyboard Events
๏ .focusin()
   -              focusin          .

๏ .focusout()

   -              focusout             .

   -   blur             focusout           .




                                               http://hyeonseok.com
Event
Keyboard Events
๏ .keydown()
  -                 keydown       .

๏ .keyup()

  -                 keyup     .

๏ .keypress()
  -               keypress    .




                                      http://hyeonseok.com
Event
Mouse Events
๏ .click()
   -             click                     .

๏ .dblclick()

   -                     click                 .

๏ .mouseup()
   -                             mouseup           .

๏ .mousedown()

   -                             mousedown             .


                                                           http://hyeonseok.com
Event
Mouse Events
๏ .toggle()
   -                                                   .

   -                               .preventDefault()
                               .

       $("td").toggle(
           function () {
               $(this).addClass("selected");
           },
           function () {
               $(this).removeClass("selected");
           }
       );




                                                           http://hyeonseok.com
Event
Mouse Events
๏ .mouseover()
  -              mouseover       .

๏ .mouseout()

  -              mouseout    .

๏ .mousemove()
  -              mousemove           .




                                 http://hyeonseok.com
Event
Mouse Events
๏ .mouseenter()
  -                   .

๏ .mouseleave()

  -               .




                          http://hyeonseok.com
Event
Mouse Events
๏ .hover()
  -
          .
      $("td").hover(
          function () {
              $(this).addClass("hover");
          },
          function () {
              $(this).removeClass("hover");
          }
      );




                                              http://hyeonseok.com
Event
Form Events
๏ .focus()
   -          focus       .

๏ .blur()

   -          blur    .




                              http://hyeonseok.com
Event
Form Events
๏ .change()
   -                            change               .

๏ .select()

   -                       select                .

๏ .submit()
   -                                submit               .

   -   return false                          .

       $('form').submit(function () {
           return false;
       });


                                                             http://hyeonseok.com
Event
Document Loading
๏ .load()
  -                         load           .

๏ .ready()

  -   DOM                              .

๏ .unload()
  -                unload          .




                                               http://hyeonseok.com
Event
Browser Events
๏ .error()
   -             error            .

๏ .resize()

   -                     resize           .

๏ .scroll()
   -               scroll             .




                                              http://hyeonseok.com
Event
Event Handler Attachment
๏ .bind()
  -                    .

๏ .unbind()

  -                    .

๏ .one()
  -   .bind()              .unbind()   .




                                           http://hyeonseok.com
Event
Event Handler Attachment
๏ .live()
   -                                            .

   -             (event delegation)
                                      .bind()       .

๏ .die()

   -   .live()                             .




                                                        http://hyeonseok.com
Event
Event Handler Attachment
๏ .delegate()
  -                        .

  -   .live()                      DOM
                    .

๏ .undelegate()

  -   .delegate()              .




                                         http://hyeonseok.com
Event
Event Handler Attachment
๏ .trigger()
   -                                          .

       $('#foo').bind('click', function() {
           alert($(this).text());
       });
       $('#foo').trigger('click');


๏ .triggerHandler()

   -   .trigger()                                 .




                                                      http://hyeonseok.com
jQuery
 effect




          http://hyeonseok.com
Effect
Basics
๏ .show()
   -                            .

๏ .hide()

   -                        .

       $('.target').hide('slow');


๏ .toggle()
   -                                .




                                        http://hyeonseok.com
Effect
Fading
๏ .fadeIn()
   -                                     .

๏ .fadeOut()

   -                                 .

       $('.target').fadeOut(2000);




                                             http://hyeonseok.com
Effect
Fading
๏ .fadeTo()
  -               .

๏ .fadeToggle()

  -                   .




                          http://hyeonseok.com
Effect
Sliding
๏ .slideUp()
   -                                   .

       $('.target').slideUp('fast');


๏ .slideDown()

   -                                       .

๏ .slideToggle()
   -                                           .




                                                   http://hyeonseok.com
Effect
Custom
๏ .animate()
  -   CSS       (    )                             .

  -   width, height, left, scrollTop, scrollLeft       .

  -   shorthand                       .

      $('#clickme').click(function() {
          $('#book').animate({
              opacity: 0.25,
              left: '+=50',
              height: 'toggle'
          }, 5000, function() {
              // Animation complete.
          });
      });




                                                           http://hyeonseok.com
Effect
Custom
๏ .stop()
   -                                            .

๏ .delay()

   -                                     .

       <p><button>Run</button></p>
       <div class="first"></div>
       <div class="second"></div>

       <script>
           $("button").click(function() {
             $("div.first").slideUp(300).delay(800).fadeIn(400);
             $("div.second").slideUp(300).fadeIn(400);
           });
       </script>




                                                                   http://hyeonseok.com
Effect
Custom
๏ .queue()
  -   jQuery          fx           (queue)
                  .

  -                        .

๏ .dequeue()

  -                    .

๏ .clearQueue()
  -                            .




                                             http://hyeonseok.com
Effect
Custom
๏ jQuery.fx.interval
   -                   .

   -              13       .

๏ jQuery.fx.off
   -                               .

   -                           .




                                       http://hyeonseok.com
jQuery
  AJAX




         http://hyeonseok.com
AJAX
Shorthand Methods
๏ .load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )
     $('#result').load('ajax/test.html');


   -   url
                                  .

     $('#result').load('ajax/test.html #container');


   -            data                  POST,               GET                 .

   -                                  .

     $('#result').load('ajax/test.html', function() {
         alert('Load was performed.');
     });




                                                                                  http://hyeonseok.com
AJAX
Shorthand Methods
๏ $.get( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] )
    $.get('ajax/test.html', function(data) {
        $('.result').html(data);
        alert('Load was performed.');
    });


๏ $.post( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] )

    $.post('ajax/test.html', function(data) {
        $('.result').html(data);
    });


๏ $.getJSON( url, [ data ], [ success(data, textStatus, jqXHR) ] )

๏ $.getScript( url, [ success(data, textStatus) ] )


                                                                                http://hyeonseok.com
AJAX
Global Ajax Event Handlers
๏ .ajaxStart( handler() )

๏ .ajaxStop( handler() )

๏ .ajaxSend( handler(event, jqXHR, ajaxOptions) )

๏ .ajaxComplete( handler(event, XMLHttpRequest, ajaxOptions) )

๏ .ajaxSuccess()

๏ .ajaxError( handler(event, jqXHR, ajaxSettings, thrownError) )




                                                               http://hyeonseok.com
AJAX
Helper Functions
๏ jQuery.param()
   -   Create a serialized representation of an array or object, suitable for
       use in a URL query string or Ajax request.

๏ .serialize()
   -   Encode a set of form elements as a string for submission.

๏ .serializeArray()
   -   Encode a set of form elements as an array of names and values.




                                                                                http://hyeonseok.com
AJAX
Low-Level Interface
๏ jQuery.ajax()
   -   Perform an asynchronous HTTP (Ajax) request.

๏ jQuery.ajaxPrefilter()
   -   Handle custom Ajax options or modify existing options before each
       request is sent and before they are processed by $.ajax().

๏ jQuery.ajaxSetup()
   -   Set default values for future Ajax requests.




                                                                       http://hyeonseok.com

More Related Content

PDF
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
PDF
Write Less Do More
Remy Sharp
 
PDF
jQuery Essentials
Bedis ElAchèche
 
PPTX
Unobtrusive javascript with jQuery
Angel Ruiz
 
PDF
jQuery Features to Avoid
dmethvin
 
PDF
jQuery Essentials
Marc Grabanski
 
PPTX
Jquery-overview
Isfand yar Khan
 
PDF
Prototype & jQuery
Remy Sharp
 
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
Write Less Do More
Remy Sharp
 
jQuery Essentials
Bedis ElAchèche
 
Unobtrusive javascript with jQuery
Angel Ruiz
 
jQuery Features to Avoid
dmethvin
 
jQuery Essentials
Marc Grabanski
 
Jquery-overview
Isfand yar Khan
 
Prototype & jQuery
Remy Sharp
 

What's hot (18)

PPTX
jQuery Fundamentals
Gil Fink
 
PDF
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
PDF
Learning jQuery in 30 minutes
Simon Willison
 
PDF
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
PDF
Organizing Code with JavascriptMVC
Thomas Reynolds
 
ODP
Introduction to jQuery
manugoel2003
 
PPTX
jQuery Presentasion
Mohammad Usman
 
PDF
jQuery%20on%20Rails%20Presentation
guestcf600a
 
PDF
jQuery: Nuts, Bolts and Bling
Doug Neiner
 
PPTX
jQuery
Dileep Mishra
 
PPT
JQuery introduction
NexThoughts Technologies
 
PPT
jQuery
Mostafa Bayomi
 
PPT
Jquery ui
adm_exoplatform
 
PPTX
jQuery quick tuts
Nasa Vietnam
 
PPTX
HirshHorn theme: how I created it
Paul Bearne
 
PDF
Using Templates to Achieve Awesomer Architecture
Garann Means
 
jQuery Fundamentals
Gil Fink
 
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Learning jQuery in 30 minutes
Simon Willison
 
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
Organizing Code with JavascriptMVC
Thomas Reynolds
 
Introduction to jQuery
manugoel2003
 
jQuery Presentasion
Mohammad Usman
 
jQuery%20on%20Rails%20Presentation
guestcf600a
 
jQuery: Nuts, Bolts and Bling
Doug Neiner
 
JQuery introduction
NexThoughts Technologies
 
Jquery ui
adm_exoplatform
 
jQuery quick tuts
Nasa Vietnam
 
HirshHorn theme: how I created it
Paul Bearne
 
Using Templates to Achieve Awesomer Architecture
Garann Means
 
Ad

Similar to jQuery Basic API (20)

PDF
Advanced JQuery Mobile tutorial with Phonegap
Rakesh Jha
 
PPTX
JQuery
Jussi Pohjolainen
 
PPTX
How to increase Performance of Web Application using JQuery
kolkatageeks
 
PPT
J query
Manav Prasad
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
PDF
Introducing jQuery
Wildan Maulana
 
PPTX
Jquery
PaRa Vaishnav
 
PDF
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
PPT
Jquery
adm_exoplatform
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PDF
Jquery presentation
Mevin Mohan
 
PPTX
jQuery
Vishwa Mohan
 
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
PPTX
J query1
Manav Prasad
 
PDF
22 j query1
Fajar Baskoro
 
PPTX
Jquery fundamentals
Salvatore Fazio
 
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
PPTX
Jquery
Pankaj Srivastava
 
PPTX
Jquery introduction
musrath mohammad
 
Advanced JQuery Mobile tutorial with Phonegap
Rakesh Jha
 
How to increase Performance of Web Application using JQuery
kolkatageeks
 
J query
Manav Prasad
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
Introducing jQuery
Wildan Maulana
 
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
Week 4 - jQuery + Ajax
baygross
 
Jquery presentation
Mevin Mohan
 
jQuery
Vishwa Mohan
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
J query1
Manav Prasad
 
22 j query1
Fajar Baskoro
 
Jquery fundamentals
Salvatore Fazio
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
Jquery introduction
musrath mohammad
 
Ad

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
This slide provides an overview Technology
mineshkharadi333
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Software Development Company | KodekX
KodekX
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 

jQuery Basic API

  • 1. jQuery Basic APIs http://hyeonseok.com
  • 3. jQuery introduction http://hyeonseok.com
  • 4. Introduction JavaScript library ๏ UI . - . ๏ . - Prototype, mooTools, YUI, Dojo, Ext JS, etc. ๏ . - . - ( , , ) . http://hyeonseok.com
  • 5. Introduction jQuery write less, do more ๏ . ๏ . ๏ . ๏ . ๏ . ๏ . ๏ MIT and GPL licenses. http://hyeonseok.com
  • 6. Introduction Installation ๏ jquery.com . <script src="jquery.js"></script> <script> // your script goes here. </script> ๏ CDN(Content delivery network) . - Google Ajax API CDN: http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js - Microsoft CDN: http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js - jQuery CDN: http://code.jquery.com/jquery-1.6.1.min.js http://hyeonseok.com
  • 8. jQuery core http://hyeonseok.com
  • 9. Core jQuery() ๏ jQuery( selector, [ context ] ) - $() . - CSS jQuery . - Selector Context - . $('div.foo').click(function() { $('span', this).addClass('bar'); }); http://hyeonseok.com
  • 10. Core jQuery() ๏ jQuery( element ), jQuery( elementArray ) - DOM . - this jQuery . $('div.foo').click(function() { $(this).slideUp(); }); - AJAX XML $ . $.post('url.xml', function(data) { var $child = $(data).find('child'); }) http://hyeonseok.com
  • 11. Core jQuery() ๏ jQuery( jQuery object ) - jQuery jQuery . ๏ jQuery() - .length 0 . http://hyeonseok.com
  • 12. Core jQuery() ๏ jQuery( html, [ ownerDocument ] ) - HTML . - jQuery createElement innerHTML . - html, title, head . - HTML . http://hyeonseok.com
  • 13. Core jQuery() ๏ jQuery( html, props ) - . $("<div/>", { "class": "test", text: "Click me!", click: function(){ $(this).toggleClass("test"); } }).appendTo("body"); http://hyeonseok.com
  • 14. Core jQuery() ๏ jQuery( callback ) - $(document).ready() DOM . $(function(){ // Document is ready }); http://hyeonseok.com
  • 15. Core ๏ jQuery.holdReady() - Holds or releases the execution of jQuery's ready event. ๏ jQuery.noConflict() - Relinquish jQuery's control of the $ variable. ๏ jQuery.sub() - Creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object. ๏ jQuery.when() - Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events. http://hyeonseok.com
  • 16. Core Chaining ๏ jQuery jQuery . - . $('div.section').hide().addClass('gone'); ๏ .end() . $('ul.first').find('.foo') .css('background-color', 'red') .end().find('.bar') .css('background-color', 'green') .end(); http://hyeonseok.com
  • 17. jQuery selectors http://hyeonseok.com
  • 18. Selectors Basic ๏ CSS . - All Selector ("*") - Class Selector (".class") - Element Selector ("element") - ID Selector ("#id") - Multiple Selector ("selector1, selector2, selectorN") http://hyeonseok.com
  • 19. Selectors Attribute ๏ Has Attribute Selector [name] ๏ Attribute Equals Selector [name="value"] ๏ Attribute Not Equal Selector [name!="value"] ๏ Attribute Starts With Selector [name^="value"] ๏ Attribute Ends With Selector [name$="value"] http://hyeonseok.com
  • 20. Selectors Attribute ๏ Multiple Attribute Selector [name="value"][name2="value2"] ๏ Attribute Contains Selector [name*="value"] ๏ Attribute Contains Prefix Selector [name|="value"] ๏ Attribute Contains Word Selector [name~="value"] http://hyeonseok.com
  • 21. Selectors Basic Filter ๏ :first Selector, :last Selector - , . ๏ :even Selector, :odd Selector - , . http://hyeonseok.com
  • 22. Selectors Basic Filter ๏ :eq() Selector - n . <table border="1"> <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr> <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr> <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr> </table> <script>$("td:eq(2)").css("color", "red");</script> http://hyeonseok.com
  • 23. Selectors Basic Filter ๏ :lt() Selector, :gt() Selector - n ,n . <table border="1"> <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr> <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr> <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr> </table> <script>$("td:lt(4)").css("color", "red");</script> http://hyeonseok.com
  • 24. Selectors Basic Filter ๏ :header Selector - . ๏ :not() Selector - . ๏ :animated Selector - . http://hyeonseok.com
  • 25. Selectors Child Filter ๏ :first-child Selector, :last-child Selector - , . ๏ :only-child Selector - . http://hyeonseok.com
  • 26. Selectors Child Filter ๏ :nth-child() Selector - n . <ul> <li>John</li> <li>Karl</li> <li>Brandon</li> </ul> <ul> <li>Sam</li> </ul> <ul> <li>Glen</li> <li>Tane</li> <li>Ralph</li> <li>David</li> </ul> <script>$("ul li:nth-child(2)").append("<span> - 2nd!</span>");</ script> http://hyeonseok.com
  • 27. Selectors Content Filter ๏ :contains() Selector - . <div>John Resig</div> <div>George Martin</div> <div>Malcom John Sinclair</div> <div>J. Ohn</div> <script> $("div:contains('John')").css("text-decoration", "underline"); </script> http://hyeonseok.com
  • 28. Selectors Content Filter ๏ :empty Selector - . ๏ :parent Selector - . ๏ :has() Selector - . http://hyeonseok.com
  • 29. Selectors Form ๏ :input Selector, :checkbox Selector, :radio Selector ๏ :text Selector, :password Selector, :file Selector ๏ :button Selector, :submit Selector, :image Selector, :reset Selector ๏ :focus selector ๏ :checked Selector ๏ :selected Selector ๏ :enabled Selector, :disabled Selector http://hyeonseok.com
  • 30. Selectors Hierarchy ๏ Child Selector ("parent > child") - . ๏ Descendant Selector ("ancestor descendant") - . ๏ Next Adjacent Selector ("prev + next") - prev next . http://hyeonseok.com
  • 31. Selectors Hierarchy ๏ Next Siblings Selector ("prev ~ siblings") - prev . <div>div (doesn't match since before #prev)</div> <span id="prev">span#prev</span> <div>div sibling</div> <div>div sibling <div id="small">div niece</div></div> <span>span sibling (not div)</span> <div>div sibling</div> <script>$("#prev ~ div").css("border", "3px groove blue");</script> http://hyeonseok.com
  • 32. Selectors Visibility Filter ๏ :visible Selector - . ๏ :hidden Selector - . http://hyeonseok.com
  • 33. jQuery traversing http://hyeonseok.com
  • 34. Traversing Tree Traversal ๏ .children() - . . <p>Hello (this is a paragraph)</p> <div><span>Hello Again (this span is a child of the a div)</span></ div> <p>And <span>Again</span> (in another paragraph)</p> <div>And One Last <span>Time</span> (most text directly in a div)</ div> <script> $("div").children().css("border-bottom", "3px double red"); </script> http://hyeonseok.com
  • 35. Traversing Tree Traversal ๏ .siblings() - . <div><span>Hello</span></div> <p class="selected">Hello Again</p> <p>And Again</p> <script> $("p").siblings(".selected").css("background", "yellow"); </script> http://hyeonseok.com
  • 36. Traversing Tree Traversal ๏ .closest() - . ๏ .find() - , jQuery , DOM . <p><span>Hello</span>, how are you?</p> <p>Me? I'm <span>good</span>.</p> <div>Did you <span>eat</span> yet?</div> <script> var $spans = $('span'); $("p").find( $spans ).css('color','red'); </script> http://hyeonseok.com
  • 37. Traversing Tree Traversal ๏ .next() - . ๏ .nextAll() - . ๏ .nextUntil() - . http://hyeonseok.com
  • 38. Traversing Tree Traversal ๏ .prev() - . ๏ .prevAll() - . ๏ .prevUntil() - . http://hyeonseok.com
  • 39. Traversing Tree Traversal ๏ .parent() - . ๏ .parents() - . ๏ .parentsUntil() - . ๏ .offsetParent() - . http://hyeonseok.com
  • 40. Traversing Filtering ๏ .eq() - n . ๏ .first() - . ๏ .last() - . ๏ .slice() - . http://hyeonseok.com
  • 41. Traversing Filtering ๏ .has() - DOM . ๏ .not() - . ๏ .is() - , jQuery . http://hyeonseok.com
  • 42. Traversing Filtering ๏ .map() - jQuery . ๏ .filter() - , jQuery , . http://hyeonseok.com
  • 43. Traversing Miscellaneous Traversing ๏ .add() - jQuery . ๏ .end() - . <p><span>Hello</span>, how are you?</p> <script> $("p").find("span").end().css("border", "2px red solid"); </script> http://hyeonseok.com
  • 44. Traversing Miscellaneous Traversing ๏ .contents() - . .children() .contents() . <div class="container"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <br /><br /> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> <br /><br /> <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p> </div> <script> $('.container').contents().filter(function() { return this.nodeType == 3; }).wrap('<p></p>').end().filter('br').remove(); </script> http://hyeonseok.com
  • 45. Traversing Miscellaneous Traversing ๏ .andSelf() - . <div> <p>First Paragraph</p> <p>Second Paragraph</p> </div> <script> $("div").find("p").andSelf().addClass("border"); </script> http://hyeonseok.com
  • 46. jQuery manipulation http://hyeonseok.com
  • 47. Manipulation General Attributes ๏ .attr() - HTML , . $('#greatphoto').attr('alt', 'Beijing Brush Seller'); - JSON . $('#greatphoto').attr({ alt: 'Beijing Brush Seller', title: 'photo by Kelly Clark' }); ๏ .removeAttr() - HTML . http://hyeonseok.com
  • 48. Manipulation General Attributes ๏ .prop() - , . - <input type="checkbox" checked="checked" /> (jQuery 1.6 ) - $('input').attr('checked') == 'checked' (string type) - $('input').prop('checked') == true (boolean type) ๏ .removeProp() - . http://hyeonseok.com
  • 49. Manipulation General Attributes ๏ .val() - (value) . $('input:text.items').val(function(index, value) { return value + ' ' + this.className; }); http://hyeonseok.com
  • 50. Manipulation Class Attribute ๏ .addClass() - (class) . ๏ .removeClass() - . $("p").removeClass("myClass noClass").addClass("yourClass"); ๏ .hasClass() - . var hasFoo = $('p').hasClass('foo'); http://hyeonseok.com
  • 51. Manipulation Class Attribute ๏ .toggleClass() - . <p class="blue">Click to toggle</p> <p class="blue highlight">highlight</p> <p class="blue">on these</p> <p class="blue">paragraphs</p> <script> $("p").click(function () { $(this).toggleClass("highlight"); }); </script> http://hyeonseok.com
  • 52. Manipulation DOM Insertion, Inside ๏ .text() - , . $('div.demo-container').text('<p>This is a test.</p>'); ๏ .html() - HTML , . $('div.demo-container').html('<p>All new content. <em>You bet!</ em></p>'); http://hyeonseok.com
  • 53. Manipulation DOM Insertion, Inside ๏ .prepend() - jQuery . ๏ .prependTo() - jQuery . http://hyeonseok.com
  • 54. Manipulation DOM Insertion, Inside ๏ .append() - jQuery . ๏ .appendTo() - jQuery . http://hyeonseok.com
  • 55. Manipulation DOM Insertion, Outside ๏ .before() - jQuery . ๏ .insertBefore() - jQuery . http://hyeonseok.com
  • 56. Manipulation DOM Insertion, Outside ๏ .after() - jQuery . ๏ .insertAfter() - jQuery . http://hyeonseok.com
  • 57. Manipulation DOM Removal ๏ .remove() - DOM . ๏ .detach() - DOM . . ๏ .empty() - DOM . http://hyeonseok.com
  • 58. Manipulation DOM Replacement ๏ .replaceWith() - jQuery . <buttondiv>First</buttondiv> <buttondiv>Second</buttondiv> <buttondiv>Third</buttondiv> <script> $("button").click(function () { $(this).replaceWith( "<div>" + $(this).text() + "</div>" ); }); </script> ๏ .replaceAll() - jQuery . http://hyeonseok.com
  • 59. Manipulation DOM Insertion, Around ๏ .wrap() - . <div><p>Hello</p></div> <div><p>cruel</p></div> <div><p>World</p></div> <script>$("p").wrap("<div></div>");</script> ๏ .wrapAll() - . <div><p>Hello</p> <p>cruel</p> <p>World</p></div> <script>$("p").wrapAll("<div></div>");</script> http://hyeonseok.com
  • 60. Manipulation DOM Insertion, Around ๏ .unwrap() - . ๏ .wrapInner() - . <p><b>Hello</b></p> <p><b>cruel</b></p> <p><b>World</b></p> <script>$("p").wrapInner("<b></b>");</script> http://hyeonseok.com
  • 61. Manipulation Copying ๏ .clone() - . <b>Hello</b><p><b>Hello</b>, how are you?</p> <script> $("b").clone().prependTo("p"); </script> http://hyeonseok.com
  • 62. Manipulation Style Properties ๏ .css() - , . - . $('#mydiv').css('color', 'green'); - index . $('div.example').css('width', function(index) { return index * 50; }); http://hyeonseok.com
  • 63. Manipulation Style Properties ๏ .height() - . var height = $('div#intro').height(); ๏ .innerHeight() - . ๏ .outerHeight() - , . - . http://hyeonseok.com
  • 64. Manipulation Style Properties ๏ .width() - . ๏ .innerWidth() - . ๏ .outerWidth() - , . http://hyeonseok.com
  • 65. Manipulation Style Properties ๏ .position() - . ๏ .offset() - . http://hyeonseok.com
  • 66. Manipulation Style Properties ๏ .scrollLeft() - . ๏ .scrollTop() - . http://hyeonseok.com
  • 67. jQuery event http://hyeonseok.com
  • 68. Event Event handling ๏ . $('a:first').click(function(ev) { $(this).css({backgroundColor: 'orange'}); return false; // Or ev.preventDefault(); }); $('a:first').click(); http://hyeonseok.com
  • 69. Event Keyboard Events ๏ .focusin() - focusin . ๏ .focusout() - focusout . - blur focusout . http://hyeonseok.com
  • 70. Event Keyboard Events ๏ .keydown() - keydown . ๏ .keyup() - keyup . ๏ .keypress() - keypress . http://hyeonseok.com
  • 71. Event Mouse Events ๏ .click() - click . ๏ .dblclick() - click . ๏ .mouseup() - mouseup . ๏ .mousedown() - mousedown . http://hyeonseok.com
  • 72. Event Mouse Events ๏ .toggle() - . - .preventDefault() . $("td").toggle( function () { $(this).addClass("selected"); }, function () { $(this).removeClass("selected"); } ); http://hyeonseok.com
  • 73. Event Mouse Events ๏ .mouseover() - mouseover . ๏ .mouseout() - mouseout . ๏ .mousemove() - mousemove . http://hyeonseok.com
  • 74. Event Mouse Events ๏ .mouseenter() - . ๏ .mouseleave() - . http://hyeonseok.com
  • 75. Event Mouse Events ๏ .hover() - . $("td").hover( function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); } ); http://hyeonseok.com
  • 76. Event Form Events ๏ .focus() - focus . ๏ .blur() - blur . http://hyeonseok.com
  • 77. Event Form Events ๏ .change() - change . ๏ .select() - select . ๏ .submit() - submit . - return false . $('form').submit(function () { return false; }); http://hyeonseok.com
  • 78. Event Document Loading ๏ .load() - load . ๏ .ready() - DOM . ๏ .unload() - unload . http://hyeonseok.com
  • 79. Event Browser Events ๏ .error() - error . ๏ .resize() - resize . ๏ .scroll() - scroll . http://hyeonseok.com
  • 80. Event Event Handler Attachment ๏ .bind() - . ๏ .unbind() - . ๏ .one() - .bind() .unbind() . http://hyeonseok.com
  • 81. Event Event Handler Attachment ๏ .live() - . - (event delegation) .bind() . ๏ .die() - .live() . http://hyeonseok.com
  • 82. Event Event Handler Attachment ๏ .delegate() - . - .live() DOM . ๏ .undelegate() - .delegate() . http://hyeonseok.com
  • 83. Event Event Handler Attachment ๏ .trigger() - . $('#foo').bind('click', function() { alert($(this).text()); }); $('#foo').trigger('click'); ๏ .triggerHandler() - .trigger() . http://hyeonseok.com
  • 84. jQuery effect http://hyeonseok.com
  • 85. Effect Basics ๏ .show() - . ๏ .hide() - . $('.target').hide('slow'); ๏ .toggle() - . http://hyeonseok.com
  • 86. Effect Fading ๏ .fadeIn() - . ๏ .fadeOut() - . $('.target').fadeOut(2000); http://hyeonseok.com
  • 87. Effect Fading ๏ .fadeTo() - . ๏ .fadeToggle() - . http://hyeonseok.com
  • 88. Effect Sliding ๏ .slideUp() - . $('.target').slideUp('fast'); ๏ .slideDown() - . ๏ .slideToggle() - . http://hyeonseok.com
  • 89. Effect Custom ๏ .animate() - CSS ( ) . - width, height, left, scrollTop, scrollLeft . - shorthand . $('#clickme').click(function() { $('#book').animate({ opacity: 0.25, left: '+=50', height: 'toggle' }, 5000, function() { // Animation complete. }); }); http://hyeonseok.com
  • 90. Effect Custom ๏ .stop() - . ๏ .delay() - . <p><button>Run</button></p> <div class="first"></div> <div class="second"></div> <script> $("button").click(function() { $("div.first").slideUp(300).delay(800).fadeIn(400); $("div.second").slideUp(300).fadeIn(400); }); </script> http://hyeonseok.com
  • 91. Effect Custom ๏ .queue() - jQuery fx (queue) . - . ๏ .dequeue() - . ๏ .clearQueue() - . http://hyeonseok.com
  • 92. Effect Custom ๏ jQuery.fx.interval - . - 13 . ๏ jQuery.fx.off - . - . http://hyeonseok.com
  • 93. jQuery AJAX http://hyeonseok.com
  • 94. AJAX Shorthand Methods ๏ .load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] ) $('#result').load('ajax/test.html'); - url . $('#result').load('ajax/test.html #container'); - data POST, GET . - . $('#result').load('ajax/test.html', function() { alert('Load was performed.'); }); http://hyeonseok.com
  • 95. AJAX Shorthand Methods ๏ $.get( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] ) $.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.'); }); ๏ $.post( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] ) $.post('ajax/test.html', function(data) { $('.result').html(data); }); ๏ $.getJSON( url, [ data ], [ success(data, textStatus, jqXHR) ] ) ๏ $.getScript( url, [ success(data, textStatus) ] ) http://hyeonseok.com
  • 96. AJAX Global Ajax Event Handlers ๏ .ajaxStart( handler() ) ๏ .ajaxStop( handler() ) ๏ .ajaxSend( handler(event, jqXHR, ajaxOptions) ) ๏ .ajaxComplete( handler(event, XMLHttpRequest, ajaxOptions) ) ๏ .ajaxSuccess() ๏ .ajaxError( handler(event, jqXHR, ajaxSettings, thrownError) ) http://hyeonseok.com
  • 97. AJAX Helper Functions ๏ jQuery.param() - Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request. ๏ .serialize() - Encode a set of form elements as a string for submission. ๏ .serializeArray() - Encode a set of form elements as an array of names and values. http://hyeonseok.com
  • 98. AJAX Low-Level Interface ๏ jQuery.ajax() - Perform an asynchronous HTTP (Ajax) request. ๏ jQuery.ajaxPrefilter() - Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax(). ๏ jQuery.ajaxSetup() - Set default values for future Ajax requests. http://hyeonseok.com