SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Prototype                  jQuery
   To and from JavaScript libraries.

    Remy Sharp (remysharp.com)
Why Prototype?


• Extends the DOM and core JavaScript
  objects
• An arsenal of utility functions

                       Based on Prototype 1.5.1 & 1.6
Why jQuery

• Centred around chaining and binding
  methods to objects and elements
• Totally encapsulated
• Aims to be exceptionally easy to develop
  with


                             Based on jQuery 1.2.1
Differences in Native Support

• Prototype has: • jQuery has:
  • Class creation  • No Conflict ($)
  • Try.these       • Effects
  • Position, Range
Non-exhaustive list, and in most case, the
functionality can be implemented with plugins.
Syntax Comparison
Dollar Variable

 • Prototype uses $ for id based selection
 • jQuery $ = CSS based selector (= $$ in
     Prototype)


Note that Prototype will return element objects or arrays of
elements for most methods. jQuery will usually return a jQuery
object (which looks like an array in Firebug).
$ Example
Prototype
$('speech1').show();


jQuery
$('#speech1').show();
CSS Based Selectors
• Prototype - $$
  To narrow down it's context use
  Element.getElementsBySelector(selector)
  (or Element.select(selector) in 1.6)
• jQuery - $
  Virtually all of jQuery's DOM selection is
  done using CSS 1-3
Selector Examples
Prototype
$$('.dialog').invoke(‘show’);

$('final-speech').getElementsBySelector ↩
('DIV.final-dialog').each(Element.hide);

// 1.6
$('final-speech').select('DIV.final- ↩
dialog').invoke('hide');
Selector Examples
jQuery
$('.dialog').show();

$('#final-speech DIV.final-dialog') ↩
  .hide();
DOM Ready Event

 • Prototype - uses Event object
 • jQuery - uses two types of syntax, both
     meaning the same thing


jQuery uses different methods to execute the ready function when
the DOM is ready, using specific methods for IE and for Safari
(http://tinyurl.com/p9pwe, http://tinyurl.com/2ya35y)
Ready Example
Prototype
Event.observe(window,'load',function(){});
Prototype 1.6
document.observe('contentloaded',
  function{});

jQuery
$(document).ready(function(){}); // or

$(function(){});
Iteration
 • Prototype - current active element, and
     position is passed in to callback function.
[el1, el2].each(fn(el, i))

 • jQuery - current element position passed
     in to callback function, and binds the
     function to current active element (i.e. this
     is set to the active element).
 •
$([el1, el2]).each(fn(i))
DOM Walking


• Prototype - up, down, next & previous
• jQuery - parent/s, children, next, prev (&
  nextAll, prevAll)
DOM Manipulation

• Prototype - Insertion class: After, Before,
  Bottom, Top, update (1.6 will add:
  Element.insert)
• jQuery - after, before, append, prepend &
  html
Element Classes

• Prototype - addClassName,
  removeClassName, toggleClassName,
  hasClassName
• jQuery - addClass, removeClass,
  toggleClass, is (for class matching)
Events

• Prototype - Event class: observe,
  stopObserving
  Prototype 1.6 will support Element.observe
• jQuery - bind, unbind (also supports
  shortcuts: .click, .dblclick, .mouse*, .ready.,
  .focus, .blur)
Bubbling

• Prototype - Event.stop()
• jQuery - return false or
  event.stopPropagation() (event is passed in
  to the callback)
Ajax
Prototype
new Ajax.Request(url[, options])


jQuery

$.ajax(options) // url included in options
Ajax - Method Comparison

    Prototype     jQuery

    onCreate     beforeSend

    onSuccess     success

   onException     error

   onComplete    complete
Ajax Examples
Prototype
new Ajax.Request(‘/profile’, {
 method: ‘post’,
 parameters:$H({‘action’:‘check_username’,
   ‘username’:$F(‘username’)}),
 onSuccess: function (j) {
   // do stuff with response
 }
});
Ajax Examples
jQuery
$.ajax({ url: '/profile',
 data: {'action':'check_username',
   'username': $('#username').val()},
 type: 'post',
 success: function (json) {
   // do stuff with response
 }
});
Plugins / Extensions
Prototype
Element.addMethods({myPlugin : function ↩
(element, args) { return element; }});

jQuery
jQuery.fn.myPlugin = function (args) ↩
{ return this; };
Browser Detection


• Prototype - Prototype.Browser.IE, .Webkit,
  etc.
• jQuery - jQuery.browser.msie, .safari, etc.
Resources
               Prototype                 jQuery

  API      prototypejs.org/api    docs.jquery.com/Core

Tutorials prototypejs.org/learn docs.jquery.com/Tutorials

 Effects      script.aculo.us      interface.eyecon.ro

Contenu connexe

En vedette

Java Servlets
Java ServletsJava Servlets
Java Servlets
Nitin Pai
 

En vedette (17)

With jQuery & CakePHP to World Domination
With jQuery & CakePHP to World DominationWith jQuery & CakePHP to World Domination
With jQuery & CakePHP to World Domination
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
DISCUS: Distributed Innovation and Scalable Collaboration in Uncertain Settings
DISCUS: Distributed Innovation and Scalable Collaboration in Uncertain SettingsDISCUS: Distributed Innovation and Scalable Collaboration in Uncertain Settings
DISCUS: Distributed Innovation and Scalable Collaboration in Uncertain Settings
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
The DISCUS project
The DISCUS projectThe DISCUS project
The DISCUS project
 
JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupal
 
서블릿(servlet)
서블릿(servlet)서블릿(servlet)
서블릿(servlet)
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
forensic document examiner using graphology science
forensic document examiner using graphology scienceforensic document examiner using graphology science
forensic document examiner using graphology science
 
Handwriting and Document Examination
Handwriting and Document ExaminationHandwriting and Document Examination
Handwriting and Document Examination
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Similaire à Prototype & jQuery

Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
rsnarayanan
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
Ravi Mone
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 

Similaire à Prototype & jQuery (20)

J query training
J query trainingJ query training
J query training
 
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
Jquery
JqueryJquery
Jquery
 
Jquery plugin development
Jquery plugin developmentJquery plugin development
Jquery plugin development
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
PHP pod mikroskopom
PHP pod mikroskopomPHP pod mikroskopom
PHP pod mikroskopom
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 

Plus de Remy Sharp

Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
Remy Sharp
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
Remy Sharp
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Remy Sharp
 

Plus de Remy Sharp (20)

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Forget the Web
Forget the WebForget the Web
Forget the Web
 
Interaction Implementation
Interaction ImplementationInteraction Implementation
Interaction Implementation
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
TwitterLib.js
TwitterLib.jsTwitterLib.js
TwitterLib.js
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
HTML5 JS APIs
HTML5 JS APIsHTML5 JS APIs
HTML5 JS APIs
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
[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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Prototype & jQuery