#1




                Day #1

          Introducing jQuery

              Wildan Maulana
       wildan.m@openthinklabs.com



     http://workshop.openthinklabs.com
Why we should use jQuery

<script type="text/javascript">
    $(function() {
      $("table tr:nth-child(even)").addClass("striped");
    });
</script>



The real power in this jQuery statement comes
from the selector, an expression
for identifying target elements on a page that
allows us to easily identify and grab
the elements we need;
What Unobtrusive JavaScript means

●   Unobtrusive JavaScript means behavior is
     separated from structure, think of it as MVC
     paradigm for JavaScript
An Example of Unobtrusive JavaScript
<button
 type="button"
 onclick="document.getElementById('xyz').style.color='red';">
   Click Me
</button>
                       <head>
                       <script type="text/javascript">
                        window.onload = function() {
                           document.getElementById('testButton').onclick = makeItRed;
                        };
                        function makeItRed() {
                           document.getElementById('xyz').style.color = 'red';
                        }
                       </script>
                       </head>
                       <body>
                       <button type="button" id="testButton">Click Me</button>
                       </body>
The Fundamental Elements and concepts of
                    jQuery
●   At its core, jQuery focuses on retrieving
      elements from our HTML pages and per-
      forming operations upon them.
●   Selector ..selector .., selector ..!
The jQuery Wapper
●   To collect a group of elements, we use the
      simple syntax :
      $(selector) or jQuery(selector)
●   $("p a") means , retrieve a group of links nested
      inside a <p> element
Query Chain
●   $("div.notLongForThisWorld").fadeOut();

●   Query Chain :

       $("div.notLongForThisWorld").fadeOut().addClass("removed");

●   $("#someElement").html("I have added some text to an element");

       same with

       $("#someElement")[0].innerHTML = "I have added some text to an element");
Query Chain - cont
●   $("div.fillMeIn").html("I have added some text to a group of
      nodes");

      same with

      var elements = $("div.fillMeIn");
      for(i=0;i<elements.length;i++)
       elements[i].innerHTML =
         "I have added some text to a group of nodes";
Advanced Selector
●   This selector is identical to the selector in CSS
●   $("p:even"); means selects all even <p> elements
●   $("tr:nth-child(1)"); means selects the first row of each table
●   $("body > div"); means selects direct <div> children of <body>.
●   $("a[href$=pdf]"); means selects link to PDF files
●   $("body > div:has(a)") means selects direct <div> children of <body> -
       containing links

       Powerfull stuff right ?!!

       You can see for full list of selector here : http://docs.jquery.com/Selectors.
About $ and jQuery()
●   $ is alias of jQuery()
●   $.trim(someString); is same with
      jQuery.trim(someString);
The document ready handler
●   To operate on a page jQuery have to wait until
      all DOM elements are fully loaded
●   Traditionally we use the onload handler
                  window.onload = function() {
                  $("table tr:nth-child(even)").addClass("even"); };

     But if we are using this method, browser will execute the load function after the
     DOM tree created and also waits until after all images and external resources are
     fully loaded and the page is displayed in the browser window
A Better Approach
●   A much better approach would be to wait only until the document structure is fully
      parsed and the browser has converted the HTML into its DOM tree form before
      executing the script to apply the rich behaviors.
●   JQuery Way :

      $(document).ready(function() {
            $("table tr:nth-child(even)").addClass("even");
      });

      or using the shorthand :

      $(function() {
        $("table tr:nth-child(even)").addClass("even");
      });
Another use of $() Function
●   Making DOM elements
<html>
 <head>
  <title>Follow me!</title>
  <script type="text/javascript" src="../scripts/jquery-1.2.1.js">
  </script>
                                                                    Ready handler that
  <script type="text/javascript">                                 creates HTML element
   $(function(){
     $("<p>Hi there!</p>").insertAfter("#followMe");
   });
  </script>                                               Existing element
                                                            tobe followed
 </head>

 <body>
  <p id="followMe">Follow me!</p>
 </body>
</html>
Extending jQuery
                                          $.fn.disable means that we’re
                                          extending the $ wrapper with a function
                                          called disable.
$.fn.disable = function() {
  return this.each(function() {
    if (typeof this.disabled != "undefined") this.disabled = true;
  });
}




       So we can use .....


              $("form#myForm input.special").disable();

              $("form#myForm input.special").disable().addClass("moreSpecial");
Using jQuery in Conjunction with Other JavaScript
                        libraries

●   If use jQuery with other library such as
    Prototype, just call :

              jQuery.noConflict()
Q&A
Reference
●   Jquery in Action, Bear Bibeault, Yehuda Katz,
    Manning

More Related Content

PPTX
Jquery plugin development
PDF
J querypractice
PDF
Javascript session june 2013 (iii) jquery json
PPTX
jQuery Best Practice
PDF
Jquery plugin development
PDF
JQuery plugin development fundamentals
ODP
Jquery Plugin
Jquery plugin development
J querypractice
Javascript session june 2013 (iii) jquery json
jQuery Best Practice
Jquery plugin development
JQuery plugin development fundamentals
Jquery Plugin

What's hot (20)

PPTX
AngulrJS Overview
PPTX
Getting classy with ES6
PPTX
Jquery introduction
PPT
Kick start with j query
PPT
Don't Worry jQuery is very Easy:Learning Tips For jQuery
PPTX
Jquery Basics
PPTX
Lecture 6: Client Side Programming 2
PPTX
Lecture 5: Client Side Programming 1
PPTX
How to increase Performance of Web Application using JQuery
PDF
Devoxx 2014-webComponents
PDF
Rails GUI Development with Ext JS
PPTX
Getting the Most Out of jQuery Widgets
PPTX
Component lifecycle hooks in Angular 2.0
PPTX
Going with style: Themes and apps for Magento Go
PDF
How Kris Writes Symfony Apps
PDF
Growing jQuery
KEY
Grails UI Primer
PPTX
Introduction to jQuery - The basics
PPTX
Everyday's JS
PPTX
Angular 2.0 Views
AngulrJS Overview
Getting classy with ES6
Jquery introduction
Kick start with j query
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Jquery Basics
Lecture 6: Client Side Programming 2
Lecture 5: Client Side Programming 1
How to increase Performance of Web Application using JQuery
Devoxx 2014-webComponents
Rails GUI Development with Ext JS
Getting the Most Out of jQuery Widgets
Component lifecycle hooks in Angular 2.0
Going with style: Themes and apps for Magento Go
How Kris Writes Symfony Apps
Growing jQuery
Grails UI Primer
Introduction to jQuery - The basics
Everyday's JS
Angular 2.0 Views
Ad

Viewers also liked (6)

PPT
Jquery presentation
PPT
jQuery Beginner
PPTX
jQuery presentation
PDF
jQuery for beginners
PPTX
jQuery PPT
PDF
Learning jQuery in 30 minutes
Jquery presentation
jQuery Beginner
jQuery presentation
jQuery for beginners
jQuery PPT
Learning jQuery in 30 minutes
Ad

Similar to Introducing jQuery (20)

PPTX
jQuery Presentasion
ODP
Jquery- One slide completing all JQuery
PPT
J query b_dotnet_ug_meet_12_may_2012
PPTX
PPTX
Introduction to jquery mobile with Phonegap
PPTX
Jquery Complete Presentation along with Javascript Basics
PPTX
Getting Started with jQuery
PDF
Introduction to jQuery
PDF
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
PDF
Jquery tutorial-beginners
PPT
Intro to jQuery
PPT
jQuery introduction/basic concept /welcome jQuery
PDF
jQuery for beginners
PDF
Introduction to jQuery
PPTX
PDF
Introduction to jQuery
PPT
JavaScript Libraries
PDF
Jquery presentation
PPTX
Getting Started with jQuery
PPTX
jQuery Presentasion
Jquery- One slide completing all JQuery
J query b_dotnet_ug_meet_12_may_2012
Introduction to jquery mobile with Phonegap
Jquery Complete Presentation along with Javascript Basics
Getting Started with jQuery
Introduction to jQuery
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Jquery tutorial-beginners
Intro to jQuery
jQuery introduction/basic concept /welcome jQuery
jQuery for beginners
Introduction to jQuery
Introduction to jQuery
JavaScript Libraries
Jquery presentation
Getting Started with jQuery

More from Wildan Maulana (20)

PDF
Hasil Pendataan Potensi Desa 2018
PDF
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
PDF
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
PDF
Pengembangan OpenThink SAS 2013-2014
PDF
ICA – AtoM : Retensi Arsip
PDF
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
PDF
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
PDF
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PDF
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
PDF
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
PDF
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
PDF
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
PDF
Instalasi dan Konfigurasi simpleSAMLphp
PDF
River Restoration in Asia and Connection Between IWRM and River Restoration
PDF
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
PPT
Penilaian Siswa di Finlandia - Pendidikan Dasar
PDF
Statistik Listrik
PDF
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
PDF
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
PDF
Menggunakan AlisJK : Equating
Hasil Pendataan Potensi Desa 2018
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Pengembangan OpenThink SAS 2013-2014
ICA – AtoM : Retensi Arsip
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi dan Konfigurasi simpleSAMLphp
River Restoration in Asia and Connection Between IWRM and River Restoration
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Penilaian Siswa di Finlandia - Pendidikan Dasar
Statistik Listrik
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
Menggunakan AlisJK : Equating

Recently uploaded (20)

PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
Revolutionizing recommendations a survey: a comprehensive exploration of mode...
PDF
Introduction to c language from lecture slides
PPT
Overviiew on Intellectual property right
PDF
substrate PowerPoint Presentation basic one
PDF
Examining Bias in AI Generated News Content.pdf
PPTX
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
PDF
Addressing the challenges of harmonizing law and artificial intelligence tech...
PPTX
Blending method and technology for hydrogen.pptx
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PDF
Child-friendly e-learning for artificial intelligence education in Indonesia:...
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Applying Agentic AI in Enterprise Automation
PDF
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PPTX
CRM(Customer Relationship Managmnet) Presentation
PDF
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
PDF
Intravenous drug administration application for pediatric patients via augmen...
PDF
Domain-specific knowledge and context in large language models: challenges, c...
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
TicketRoot: Event Tech Solutions Deck 2025
Revolutionizing recommendations a survey: a comprehensive exploration of mode...
Introduction to c language from lecture slides
Overviiew on Intellectual property right
substrate PowerPoint Presentation basic one
Examining Bias in AI Generated News Content.pdf
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
Addressing the challenges of harmonizing law and artificial intelligence tech...
Blending method and technology for hydrogen.pptx
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
Child-friendly e-learning for artificial intelligence education in Indonesia:...
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Applying Agentic AI in Enterprise Automation
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
CRM(Customer Relationship Managmnet) Presentation
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
Intravenous drug administration application for pediatric patients via augmen...
Domain-specific knowledge and context in large language models: challenges, c...

Introducing jQuery

  • 1. #1 Day #1 Introducing jQuery Wildan Maulana [email protected] http://workshop.openthinklabs.com
  • 2. Why we should use jQuery <script type="text/javascript"> $(function() { $("table tr:nth-child(even)").addClass("striped"); }); </script> The real power in this jQuery statement comes from the selector, an expression for identifying target elements on a page that allows us to easily identify and grab the elements we need;
  • 3. What Unobtrusive JavaScript means ● Unobtrusive JavaScript means behavior is separated from structure, think of it as MVC paradigm for JavaScript
  • 4. An Example of Unobtrusive JavaScript <button type="button" onclick="document.getElementById('xyz').style.color='red';"> Click Me </button> <head> <script type="text/javascript"> window.onload = function() { document.getElementById('testButton').onclick = makeItRed; }; function makeItRed() { document.getElementById('xyz').style.color = 'red'; } </script> </head> <body> <button type="button" id="testButton">Click Me</button> </body>
  • 5. The Fundamental Elements and concepts of jQuery ● At its core, jQuery focuses on retrieving elements from our HTML pages and per- forming operations upon them. ● Selector ..selector .., selector ..!
  • 6. The jQuery Wapper ● To collect a group of elements, we use the simple syntax : $(selector) or jQuery(selector) ● $("p a") means , retrieve a group of links nested inside a <p> element
  • 7. Query Chain ● $("div.notLongForThisWorld").fadeOut(); ● Query Chain : $("div.notLongForThisWorld").fadeOut().addClass("removed"); ● $("#someElement").html("I have added some text to an element"); same with $("#someElement")[0].innerHTML = "I have added some text to an element");
  • 8. Query Chain - cont ● $("div.fillMeIn").html("I have added some text to a group of nodes"); same with var elements = $("div.fillMeIn"); for(i=0;i<elements.length;i++) elements[i].innerHTML = "I have added some text to a group of nodes";
  • 9. Advanced Selector ● This selector is identical to the selector in CSS ● $("p:even"); means selects all even <p> elements ● $("tr:nth-child(1)"); means selects the first row of each table ● $("body > div"); means selects direct <div> children of <body>. ● $("a[href$=pdf]"); means selects link to PDF files ● $("body > div:has(a)") means selects direct <div> children of <body> - containing links Powerfull stuff right ?!! You can see for full list of selector here : http://docs.jquery.com/Selectors.
  • 10. About $ and jQuery() ● $ is alias of jQuery() ● $.trim(someString); is same with jQuery.trim(someString);
  • 11. The document ready handler ● To operate on a page jQuery have to wait until all DOM elements are fully loaded ● Traditionally we use the onload handler window.onload = function() { $("table tr:nth-child(even)").addClass("even"); }; But if we are using this method, browser will execute the load function after the DOM tree created and also waits until after all images and external resources are fully loaded and the page is displayed in the browser window
  • 12. A Better Approach ● A much better approach would be to wait only until the document structure is fully parsed and the browser has converted the HTML into its DOM tree form before executing the script to apply the rich behaviors. ● JQuery Way : $(document).ready(function() { $("table tr:nth-child(even)").addClass("even"); }); or using the shorthand : $(function() { $("table tr:nth-child(even)").addClass("even"); });
  • 13. Another use of $() Function ● Making DOM elements <html> <head> <title>Follow me!</title> <script type="text/javascript" src="../scripts/jquery-1.2.1.js"> </script> Ready handler that <script type="text/javascript"> creates HTML element $(function(){ $("<p>Hi there!</p>").insertAfter("#followMe"); }); </script> Existing element tobe followed </head> <body> <p id="followMe">Follow me!</p> </body> </html>
  • 14. Extending jQuery $.fn.disable means that we’re extending the $ wrapper with a function called disable. $.fn.disable = function() { return this.each(function() { if (typeof this.disabled != "undefined") this.disabled = true; }); } So we can use ..... $("form#myForm input.special").disable(); $("form#myForm input.special").disable().addClass("moreSpecial");
  • 15. Using jQuery in Conjunction with Other JavaScript libraries ● If use jQuery with other library such as Prototype, just call : jQuery.noConflict()
  • 16. Q&A
  • 17. Reference ● Jquery in Action, Bear Bibeault, Yehuda Katz, Manning