SlideShare a Scribd company logo
1 of 33
Download to read offline
JQuery

       SCOTT RYAN
        MAY 2008
SCOTT@THERYANSPLACE.COM
Agenda

  Web Development Introduction
  JQuery Introduction
  Selectors
  Modifiers
  Events
  Animation
  Ajax
  Plugins
Best Practices

  Separation of Concerns
     HTML – Layout

     CSS – Look and Feel

     JavaScript – Event Handling and Dynamic Behavior

     Ajax – Remote access and dynamic data
Why JQuery

  Captures standard pattern
     Select ,add or filter, manipulate, repeat

     Unobtrusive JavaScript

  Table Striping Example
Table Striping (Dom Code)

var tables =
  document.getElementsByTagName(quot;tablequot;);
  for ( var t = 0; t < tables.length; t++ )
{
  var rows = tables[t].getElementsByTagName(quot;trquot;);
  for ( var i = 1; i < rows.length; i += 2 ) if ( !/(^|
  s)odd(s|$)/.test( rows[i].className ) )
  rows[i].className += quot; oddquot;;
}
Table Striping (Prototype)

$$(quot;tablequot;).each(function(table)
{
   Selector.findChildElements(table,
  [quot;trquot;]) .findAll(function(row,i){ return i % 2 == 1;
}) .invoke(quot;addClassNamequot;, quot;oddquot;);
});
Table Striping (jQuery)

  $(quot;tr:nth-child(odd)quot;).addClass(quot;oddquot;);
JQuery Wrapper

  $(selector) or jQuery(selector)
  Returns an array of Dom elements
  Includes many methods
     Example
      $(“div.fademeout”).fadeOut();

  Can be chained and always return a new array of
   elements
  Supports CSS selectors and custom selectors
Document Ready Handler

  $(document).ready(function(){});
  $(function(){});
     Runs when DOM is loaded

     Cross Browser

     Don’t need to wait for resources
Extending JQuery

  $.fn.samplefunc = function()
   {
   Return
   this.each(
   function(){code goes here});
   }


  $(‘#sample’).samplefunc().addClass(‘NewClass’);
Other Libraries

  jQuery.noConflict();
Select
Selectors

  Generic
     Element Name (a, p, img, tr, etc)

     ID (#theId)

     Class (.theclassname)
       a#theId.theclassname
       p   a.theclassname
  Parent – Child
     ul.myList > li > a
Positional Selectors

  :first
  :last
  :first-child
  :last-child
  :only-child
  :nth-child(2)
  :nth-child(even)
Special Selectors

  :button                      :submit
  :checkbox                    :selected
  :checked                     :text
  :contains(text string)       :visible
  :enabled
  :disabled
  :input
  :hidden
Managing the Wrapped Set

  size
  get(x)
  index(element)
  add(expression)
  not(expression)
  filter(expression)
  Slice(begin, end)
Selection Demo

  $(‘#hibiscus’)
  $(‘img[alt],img[title]’)
  $('img[alt]').add('img[title]')
  $('li > a')
  $('li > a:first')
  $(quot;#aTextFieldquot;).attr(quot;valuequot;,quot;testquot;)
  $(‘input[type=text]’)
  $(‘a[href$=.pdf]’)
  $(‘div[title^=my]’)
More Sample Selectors

  $(‘li:has(a)’);
  $(‘li a’);
Create/Filter/Manipulate
Creating HTML

  $(“<div>Hello</div>”) or $(“<div>”)


  $(“<div class=‘foo’>I have Foo</div><div>I Don’t</
   div>”)
  .filter(“.foo”)
  .click(function(){alert (‘I am Foo’);})
  .end()
  .appendTo(“#somedivoutthere”);
DOM Manipulation

  Each accesses every element in the wrapped set
  Attr get and set values
     Can use json syntax

     Attr(title:’test’, value:’yes’)

     removeAttr

     $(“a[href^http://]”).attr(“target”,”_blank”);
More Manipulation

  addClass                    append, appendTo
  removeClass                 prepend, prependTo
  toggleClass                 before,insertBefore
  css(name,value)             after, insertAfter
  width,height, css           wrap, wrapAll,wrapInner
  hasClass, getClassNames     remove
  html, html(data)            empty
  text , text(data)           replaceWith
                               (after.remove)
Replacing Elements

  $(‘#divToReplace’)
  .replaceWith(‘<p>This is new Data</p>’)
  .remove();
Events and Event Model

  Dom Level 0 Event Model
     Single Events

     Event Class (Proprietary)

  Dom Level 2 Event Model
     Multi Event

     Event Class

     Non IE

  IE Event Model
  Propagation (Bubble and Capture)
JQuery Event Model

  Unified Event Model
  Unified Event Object
  Supports Model 2 Semantics
  Propagation
     Cascade

     Bubble
Event Semantics

  bind(eventType,data,listener)
  eventTypeName(listener)
  one(eventType, data,listener)
  unbind(eventType, listener)
  unbind(event)
  trigger(eventType)
  toggle(oddListener,evenListener)
Simple Bind

  $(function(){
$(‘#sample’)
.bind(‘click’,clickOne)
.bind(‘click’,clickTwo)
.bind(‘click’,clickThree)
.bind(‘mouseover’,mouse);
Event Sample (Toggle/Inline)

$(function(){
   $(‘#sample’).toggle(
      function(event){
        $(event.target).css(‘opacity’0.4);},
      function(event){
        $(event.target).css(‘opacity”,1.0;}
   );
});
Event Sample (Hover/External)

$(‘#sample’)
  .bind(‘mouseover’ , report)
  .bind(‘mouseout’ , report);

function report (event) {
  $(‘#output’).append(‘<div>’+event.type+’</div>’);
}

$(‘#sample’).hover(report , report);
Animation and Effects

  show (speed, callback)
  hide(speed, callback)
  toggle(speed, callback)
     Callback is a function that is passed a reference to this as the
      calling element.
  fadeIn, fadeOut, fadeTo
  slideDown, slideUp, slideToggle
  Custom animations
JQuery Utility Functions

  browser, box model, float style flags
  trim
  each
  grep
  inArray, makeArray, unique, extend
  getScript
Plugins

  Complex extensions
  Should be developed to work with other libraries
  Custom Utility functions
  Custom wrapped methods
  Form, Dimensions, Live Query, UI, MarkitUp
  Beware of the $ but not too timid
  Naming jquery.pluginname.js
  Parameter Tricks
Ajax

  load (url, parameters, callback)
  serialize, serializeArray
  get
  getJSON
  post
  ajax

More Related Content

What's hot

Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Railsshen liu
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏Masahiro Akita
 
React.js: Beyond the Browser
React.js: Beyond the BrowserReact.js: Beyond the Browser
React.js: Beyond the Browsergarbles
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS OverviewEyal Vardi
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterciconf
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web ComponentsFelix Arntz
 
Delivering a Responsive UI
Delivering a Responsive UIDelivering a Responsive UI
Delivering a Responsive UIRebecca Murphey
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
 
Final tagless and cats mtl
Final tagless and cats mtl Final tagless and cats mtl
Final tagless and cats mtl Alexander Zaidel
 
Лабораторная работа №1
Лабораторная работа №1Лабораторная работа №1
Лабораторная работа №1Alexey Potopakhin
 

What's hot (20)

Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Coding website
Coding websiteCoding website
Coding website
 
HTML5 - Pedro Rosa
HTML5 - Pedro RosaHTML5 - Pedro Rosa
HTML5 - Pedro Rosa
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Rails
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
 
React.js: Beyond the Browser
React.js: Beyond the BrowserReact.js: Beyond the Browser
React.js: Beyond the Browser
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
SQLAlchemy Seminar
SQLAlchemy SeminarSQLAlchemy Seminar
SQLAlchemy Seminar
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Delivering a Responsive UI
Delivering a Responsive UIDelivering a Responsive UI
Delivering a Responsive UI
 
jQuery
jQueryjQuery
jQuery
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
Final tagless and cats mtl
Final tagless and cats mtl Final tagless and cats mtl
Final tagless and cats mtl
 
Лабораторная работа №1
Лабораторная работа №1Лабораторная работа №1
Лабораторная работа №1
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
 
Jquery
JqueryJquery
Jquery
 

Similar to DOSUG Intro to JQuery JavaScript Framework

The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryQConLondon2008
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)jeresig
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)jeresig
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jeresig
 
History of jQuery
History of jQueryHistory of jQuery
History of jQueryjeresig
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQueryPaul Bakaus
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuerykatbailey
 
Web accessibility
Web accessibilityWeb accessibility
Web accessibilityEb Styles
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in SeasideESUG
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshowsblackman
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
jQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjeresig
 

Similar to DOSUG Intro to JQuery JavaScript Framework (20)

The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
Jslunch6
Jslunch6Jslunch6
Jslunch6
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQuery
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
 
jQuery for Seaside
jQuery for SeasidejQuery for Seaside
jQuery for Seaside
 
Web accessibility
Web accessibilityWeb accessibility
Web accessibility
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in Seaside
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
 
DjangoCon09: The Test Client
DjangoCon09: The Test ClientDjangoCon09: The Test Client
DjangoCon09: The Test Client
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
YUI 3
YUI 3YUI 3
YUI 3
 
jQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UI
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 

More from Matthew McCullough

iPhone & Java Web Services, Take 2
iPhone & Java Web Services, Take 2iPhone & Java Web Services, Take 2
iPhone & Java Web Services, Take 2Matthew McCullough
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSMatthew McCullough
 
Terracotta Java Scalability - Stateless Versus Stateful Apps
Terracotta Java Scalability - Stateless Versus Stateful AppsTerracotta Java Scalability - Stateless Versus Stateful Apps
Terracotta Java Scalability - Stateless Versus Stateful AppsMatthew McCullough
 
DOSUG GridGain Java Grid Computing Made Simple
DOSUG GridGain Java Grid Computing Made SimpleDOSUG GridGain Java Grid Computing Made Simple
DOSUG GridGain Java Grid Computing Made SimpleMatthew McCullough
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideMatthew McCullough
 
DOSUG Java FX Script From Takeoff To Cruising Altitude
DOSUG Java FX Script From Takeoff To Cruising AltitudeDOSUG Java FX Script From Takeoff To Cruising Altitude
DOSUG Java FX Script From Takeoff To Cruising AltitudeMatthew McCullough
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianMatthew McCullough
 

More from Matthew McCullough (11)

iPhone & Java Web Services, Take 2
iPhone & Java Web Services, Take 2iPhone & Java Web Services, Take 2
iPhone & Java Web Services, Take 2
 
iPhone & Java Web Services
iPhone & Java Web ServicesiPhone & Java Web Services
iPhone & Java Web Services
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCS
 
Terracotta Java Scalability - Stateless Versus Stateful Apps
Terracotta Java Scalability - Stateless Versus Stateful AppsTerracotta Java Scalability - Stateless Versus Stateful Apps
Terracotta Java Scalability - Stateless Versus Stateful Apps
 
DOSUG GridGain Java Grid Computing Made Simple
DOSUG GridGain Java Grid Computing Made SimpleDOSUG GridGain Java Grid Computing Made Simple
DOSUG GridGain Java Grid Computing Made Simple
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
 
DOSUG Wicket 101
DOSUG Wicket 101DOSUG Wicket 101
DOSUG Wicket 101
 
EasyMock 101
EasyMock 101EasyMock 101
EasyMock 101
 
DOSUG Java FX Script From Takeoff To Cruising Altitude
DOSUG Java FX Script From Takeoff To Cruising AltitudeDOSUG Java FX Script From Takeoff To Cruising Altitude
DOSUG Java FX Script From Takeoff To Cruising Altitude
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om Sivanesian
 
DOSUG Tech Overview of XAware
DOSUG Tech Overview of XAwareDOSUG Tech Overview of XAware
DOSUG Tech Overview of XAware
 

Recently uploaded

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

DOSUG Intro to JQuery JavaScript Framework

  • 1. JQuery SCOTT RYAN MAY 2008 SCOTT@THERYANSPLACE.COM
  • 2. Agenda   Web Development Introduction   JQuery Introduction   Selectors   Modifiers   Events   Animation   Ajax   Plugins
  • 3. Best Practices   Separation of Concerns   HTML – Layout   CSS – Look and Feel   JavaScript – Event Handling and Dynamic Behavior   Ajax – Remote access and dynamic data
  • 4. Why JQuery   Captures standard pattern   Select ,add or filter, manipulate, repeat   Unobtrusive JavaScript   Table Striping Example
  • 5. Table Striping (Dom Code) var tables = document.getElementsByTagName(quot;tablequot;); for ( var t = 0; t < tables.length; t++ ) { var rows = tables[t].getElementsByTagName(quot;trquot;); for ( var i = 1; i < rows.length; i += 2 ) if ( !/(^| s)odd(s|$)/.test( rows[i].className ) ) rows[i].className += quot; oddquot;; }
  • 6. Table Striping (Prototype) $$(quot;tablequot;).each(function(table) { Selector.findChildElements(table, [quot;trquot;]) .findAll(function(row,i){ return i % 2 == 1; }) .invoke(quot;addClassNamequot;, quot;oddquot;); });
  • 7. Table Striping (jQuery)   $(quot;tr:nth-child(odd)quot;).addClass(quot;oddquot;);
  • 8. JQuery Wrapper   $(selector) or jQuery(selector)   Returns an array of Dom elements   Includes many methods   Example   $(“div.fademeout”).fadeOut();   Can be chained and always return a new array of elements   Supports CSS selectors and custom selectors
  • 9. Document Ready Handler   $(document).ready(function(){});   $(function(){});   Runs when DOM is loaded   Cross Browser   Don’t need to wait for resources
  • 10. Extending JQuery   $.fn.samplefunc = function() { Return this.each( function(){code goes here}); }   $(‘#sample’).samplefunc().addClass(‘NewClass’);
  • 13. Selectors   Generic   Element Name (a, p, img, tr, etc)   ID (#theId)   Class (.theclassname)   a#theId.theclassname   p a.theclassname   Parent – Child   ul.myList > li > a
  • 14. Positional Selectors   :first   :last   :first-child   :last-child   :only-child   :nth-child(2)   :nth-child(even)
  • 15. Special Selectors   :button   :submit   :checkbox   :selected   :checked   :text   :contains(text string)   :visible   :enabled   :disabled   :input   :hidden
  • 16. Managing the Wrapped Set   size   get(x)   index(element)   add(expression)   not(expression)   filter(expression)   Slice(begin, end)
  • 17. Selection Demo   $(‘#hibiscus’)   $(‘img[alt],img[title]’)   $('img[alt]').add('img[title]')   $('li > a')   $('li > a:first')   $(quot;#aTextFieldquot;).attr(quot;valuequot;,quot;testquot;)   $(‘input[type=text]’)   $(‘a[href$=.pdf]’)   $(‘div[title^=my]’)
  • 18. More Sample Selectors   $(‘li:has(a)’);   $(‘li a’);
  • 20. Creating HTML   $(“<div>Hello</div>”) or $(“<div>”)   $(“<div class=‘foo’>I have Foo</div><div>I Don’t</ div>”)   .filter(“.foo”)   .click(function(){alert (‘I am Foo’);})   .end()   .appendTo(“#somedivoutthere”);
  • 21. DOM Manipulation   Each accesses every element in the wrapped set   Attr get and set values   Can use json syntax   Attr(title:’test’, value:’yes’)   removeAttr   $(“a[href^http://]”).attr(“target”,”_blank”);
  • 22. More Manipulation   addClass   append, appendTo   removeClass   prepend, prependTo   toggleClass   before,insertBefore   css(name,value)   after, insertAfter   width,height, css   wrap, wrapAll,wrapInner   hasClass, getClassNames   remove   html, html(data)   empty   text , text(data)   replaceWith (after.remove)
  • 23. Replacing Elements   $(‘#divToReplace’)   .replaceWith(‘<p>This is new Data</p>’)   .remove();
  • 24. Events and Event Model   Dom Level 0 Event Model   Single Events   Event Class (Proprietary)   Dom Level 2 Event Model   Multi Event   Event Class   Non IE   IE Event Model   Propagation (Bubble and Capture)
  • 25. JQuery Event Model   Unified Event Model   Unified Event Object   Supports Model 2 Semantics   Propagation   Cascade   Bubble
  • 26. Event Semantics   bind(eventType,data,listener)   eventTypeName(listener)   one(eventType, data,listener)   unbind(eventType, listener)   unbind(event)   trigger(eventType)   toggle(oddListener,evenListener)
  • 28. Event Sample (Toggle/Inline) $(function(){ $(‘#sample’).toggle( function(event){ $(event.target).css(‘opacity’0.4);}, function(event){ $(event.target).css(‘opacity”,1.0;} ); });
  • 29. Event Sample (Hover/External) $(‘#sample’) .bind(‘mouseover’ , report) .bind(‘mouseout’ , report); function report (event) { $(‘#output’).append(‘<div>’+event.type+’</div>’); } $(‘#sample’).hover(report , report);
  • 30. Animation and Effects   show (speed, callback)   hide(speed, callback)   toggle(speed, callback)   Callback is a function that is passed a reference to this as the calling element.   fadeIn, fadeOut, fadeTo   slideDown, slideUp, slideToggle   Custom animations
  • 31. JQuery Utility Functions   browser, box model, float style flags   trim   each   grep   inArray, makeArray, unique, extend   getScript
  • 32. Plugins   Complex extensions   Should be developed to work with other libraries   Custom Utility functions   Custom wrapped methods   Form, Dimensions, Live Query, UI, MarkitUp   Beware of the $ but not too timid   Naming jquery.pluginname.js   Parameter Tricks
  • 33. Ajax   load (url, parameters, callback)   serialize, serializeArray   get   getJSON   post   ajax