SlideShare a Scribd company logo
jQuery
:


•
•
•   etc..
:


•
•
•   etc..


            jQuery OK!!
“jQuery”
HTML/CSS          JavaScript
Web
• jQuery
 •   jQuery
 •   DOM
 •
 •
 •
•
About Me



• WEB             Developer / PHP / CakePHP / HTML / CSS / jQuery / PostgreSQL /
    MySQL / iPhone /       /     /    /    /     /           /         / no more



•   BLOG: http://php-tips.com/
•   TWITTER: @nojimage
•   FACEBOOK: http://www.facebook.com/nojimage
About   ?
?
About jQuery




   HTML/CSS
  JavaScript
About jQuery

          :   http://jquery.com/
• CSS                 DOM
•         DOM Element   /
•
•
• GPL/MIT
Getting started with jQuery
•   jQuery
    •          1.4.3 (2010/10/30   )


•   <script>
Getting started with jQuery
•   jQuery
    •           1.4.3 (2010/10/30   )


•   <script type="text/javascript"
    <script>
     src="js/jquery-1.4.3.min.js"></script>
Getting started with jQuery
•   jQuery
    •           1.4.3 (2010/10/30   )


•   <script type="text/javascript"
    <script>
     src="js/jquery-1.4.3.min.js"></script>
    <script type="text/javascript"><!--
    $(document).ready(function(){
         /*                             */

    };
    // --></script>
Manipulate DOM
DOM
DOM =
DOM = Document Object Model
DOM = Document Object Model

• HTML        XML             JavaScript
                                           API

•
DOM = Document Object Model



                     title

             head
                      ...

   html                            li

                      h1      ul
             body                  ...
                     div      p
How to select DOM Elements
        with jQuery
jQuery     CSS
     DOM
$('ul');
$('ul');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('ul');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#title');
$('#title');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#title');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('.message');
$('.message');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('.message');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
    <li class="message">Hello World.</li>
    <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents p');
$('#contents p');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents p');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</
p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
DOM Traversing



  DOM
$('#contents').next();
$('#contents').next();

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents').next();

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents').next();

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents').find('p');
$('#contents').find('p');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents').find('p');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('#contents').find('p');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('li.message').parent('div');
$('li.message').parent('div');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('li.message').parent('div');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</p>
<ul>
    <li class="message">Hello World.</li>
    <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$('li.message').parent('div');

<div id="header">
<p id="title">Foobar Website</p>
<ul>
  <li>Home</li>
  <li>Products</li>
  <li>Contacts</li>
</ul>
</div>
<div id="contents">
<p>jQuery is a fast and concise JavaScript Library.</
p>
<ul>
  <li class="message">Hello World.</li>
  <li class="message">Let's eat pudding.</li>
</ul>
</div>
<div id="footer">Copyright 2010 Foobar Inc.</div>
$ ?
$ is jQuery

                                 $ jQuery


// <div id="contents">
$('#contents').next();

// <div id="contents">       p
$('#contents').find('p');

// <input id="email"/>             form
$('input#email').parent('form');
$ is jQuery

                                  $ jQuery


// <div id="contents">
jQuery('#contents').next();

// <div id="contents">        p
jQuery('#contents').find('p');

// <input id="email"/>            form
jQuery('input#email').parent('form');
Manipulate DOM elements



jQuery   DOM
Manipulate DOM elements

• append()

• prepend()

• remove()
Manipulate DOM elements

• html(val)
         HTML val
• text(val)
          val
  val
Manipulate DOM elements

• attr(key,   val)
       key      val
• removeAttr(key)
      key
Manipulate DOM elements

• addClass(val)
      class   val
• removeClass(val)
      class   val
• css(key,     val)
       style          key: val
Demo
Event Handler
jQuery プラグイン作成入門
Event Handler
•




    •

    •

    •

    •

    •
Event Handler

• click(func)


 onClick


$('a').click(function(){
    //                      Move to
      return confirm('Move to "' + this.href + '"');
});
Event Handler

• ready(func)


 •   DOM




$(document).ready(function(){
    //                        Complete
      alert('Complete');
});
Event Handler
•
    •   change()
    •   dbclick()
    •   error()
    •   focus()
    •   keydown()
    •   keypress()
    •   keyup()
    •   load()
    •   mousedown()
    •   mousemove()
    •   .....
Animation with jQuery
jQuery
Animation
•   jQuery
    • hide()   / show()
    • slideUp()   / slideDown()
    • fadeOut()   / fadeIn()

•
Create Animation



• animate(properties,                   options)

$('.move-right').click(function(){ // .move-right
      $('#box').animate({
          'left': '+=50px' // #box       50px
      }, {
             duration: "slow", //
             //
             complete: function(){ alert('Move!'); }
      });
});
Letʼs create jQuery Plugin!
jQuery   !
Plugin?
•

    <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
    <script type="text/javascript" src="js/jquery.plugin_name.js"></script>
    <script type="text/javascript"><!--
    $(document).ready(function(){


            $.pluginName();
    });
    // --></script>
Why Plugin?
•

    •




    •   HTML   JavaScript



    •
How to create Plugin
•
    •   jQuery

    •   $(‘selector’)   jQuery
$.pluginName(params);
$.pluginName(params);


;(function($){




})(jQuery);
$.pluginName(params);


;(function($){ ←




})(jQuery);   ←
$.pluginName(params);


;(function($){

    $.extend({




    });

})(jQuery);
$.pluginName(params);


;(function($){

    $.extend({

          "pluginName" : function(params){



          }

    });

})(jQuery);
$.pluginName(params);


;(function($){

    $.extend({

          "pluginName" : function(params){

              // do something...

          }

    });

})(jQuery);
$(selector).pluginName(params);
$.fn
$(selector).pluginName(params);


;(function($){




})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.extend({




    });

})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.extend({

          "pluginName" : function(params){




          }

    });

})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.extend({

          "pluginName" : function(params){

              // do something.

              return this;
          }

    });

})(jQuery);
$(selector).pluginName(params);


;(function($){




})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.pluginName = function(params){




    };

})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.pluginName = function(params){

         // do something.

         return this;
    };

})(jQuery);
$(selector).pluginName(params);


;(function($){

    $.fn.pluginName = function(params){

         // do something.


    };
         return this;
                        ←
})(jQuery);
$(‘#target’).someFunc()
    .addClass(‘someClass’)
    .slideDown();
Tips 1

•                  (      )

    $.pluginName({foo: true})
(function($){

    $.fn.pluginName = function(params){

         // override input params
   	     params = $.extend({}, $.fn.pluginName.defaults, params);

         // do something...

    };

    // default values
    $.fn.pluginName.defaults = {
         foo: 'hoge',
         bar: 'fuga'
    };

})(jQuery);
(function($){

    $.fn.pluginName = function(params){

         // override input params
   	     params = $.extend({}, $.fn.pluginName.defaults, params);

         // do something...

    };

    // default values
    $.fn.pluginName.defaults = {
         foo: 'hoge',
         bar: 'fuga'
                                   }
    };

})(jQuery);
(function($){

    $.fn.pluginName = function(params){

         // override input params         ↓
   	     params = $.extend({}, $.fn.pluginName.defaults, params);

         // do something...

    };

    // default values
    $.fn.pluginName.defaults = {
         foo: 'hoge',
         bar: 'fuga'
                                   }
    };

})(jQuery);
Tips 2

•
(function($){

    var localFunction = function(params) {

         alert('local function');

    };

    $.fn.pluginName = function(params){

   	     // do something..

         localFunction(params);

         // do something..
    };

})(jQuery);
(function($){

    var localFunction = function(params) {
                                             }
         alert('local function');

    };

    $.fn.pluginName = function(params){

   	     // do something..

         localFunction(params);

         // do something..
    };

})(jQuery);
(function($){

    var localFunction = function(params) {
                                             }
         alert('local function');

    };

    $.fn.pluginName = function(params){

   	     // do something..

         localFunction(params);     }
         // do something..
    };

})(jQuery);
Tips 3
•
    •   $.pluginName.funcA()
    •   $.pluginName.funcB()
(function($){

    $.pluginName = {};




})(jQuery);
(function($){

    $.pluginName = {};



    $.pluginName.FuncA = function(){

         // do something...

    };




})(jQuery);
(function($){

    $.pluginName = {};



    $.pluginName.FuncA = function(){

         // do something...        } $.pluginName.FuncA()
    };




})(jQuery);
(function($){

    $.pluginName = {};



    $.pluginName.FuncA = function(){

         // do something...

    };

    $.pluginName.FuncB = function(){

         // do something...

    };

})(jQuery);
(function($){

    $.pluginName = {};



    $.pluginName.FuncA = function(){

         // do something...

    };

    $.pluginName.FuncB = function(){

         // do something...
                                   } $.pluginName.FuncB()
    };

})(jQuery);
Example.
jQuery.formControll.js
jQuery.formControll.js

•                        TAB, Enter



    • Meta + Enter
    •
    • textarea     TAB
Demo
Thank you for your listening!!

More Related Content

PPT
Jquerymobile ppt
PDF
Jquery Framework
PDF
jQuery for beginners
KEY
Javascript4
PDF
Intro to jQuery UI
PPTX
Concevoir un thème pour Wordpress
PDF
Macdom html preprocesor
KEY
jQuery入門
Jquerymobile ppt
Jquery Framework
jQuery for beginners
Javascript4
Intro to jQuery UI
Concevoir un thème pour Wordpress
Macdom html preprocesor
jQuery入門

What's hot (11)

PDF
20110128 HTML5 Markup My Blog
PPTX
Tjejer kodar 100 - Dag 2 - HTML & CSS
KEY
Selectors & Traversing
PDF
tmn - Introdução ao DOM
PPTX
Jquery Introduction Hebrew
PDF
jQuery Mobileではじめるモバイルサイト/アプリ制作
PPTX
10 Programación Web con .NET y C#
PDF
PDF
Javascript and jQuery for Mobile
PDF
Краткий обзор библиотеки YUI
PPTX
Asp .net Jquery
20110128 HTML5 Markup My Blog
Tjejer kodar 100 - Dag 2 - HTML & CSS
Selectors & Traversing
tmn - Introdução ao DOM
Jquery Introduction Hebrew
jQuery Mobileではじめるモバイルサイト/アプリ制作
10 Programación Web con .NET y C#
Javascript and jQuery for Mobile
Краткий обзор библиотеки YUI
Asp .net Jquery
Ad

Viewers also liked (6)

PDF
Composerはじめました
ODP
Cake php4designers
PDF
CakePHP SessionAcl Component
PDF
MVCのVを極めしWebデザイナーになる - CakePHP勉強会
PDF
PHPTAL with CakePHP
PDF
Plugin for CakePHP2.0
Composerはじめました
Cake php4designers
CakePHP SessionAcl Component
MVCのVを極めしWebデザイナーになる - CakePHP勉強会
PHPTAL with CakePHP
Plugin for CakePHP2.0
Ad

jQuery プラグイン作成入門