SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Masahiro Akita
 
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
ciconf
 
Delivering a Responsive UI
Delivering a Responsive UIDelivering a Responsive UI
Delivering a Responsive UI
Rebecca Murphey
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
Remy Sharp
 

Was ist angesagt? (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
 

Ähnlich wie 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 Query
QConLondon2008
 
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
deimos
 
Web accessibility
Web accessibilityWeb accessibility
Web accessibility
Eb Styles
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
sblackman
 

Ähnlich wie 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)
 

Mehr von Matthew McCullough

Mehr von 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
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

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