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

Tendances

Identification of various breeds of poultry
Identification of various breeds of poultryIdentification of various breeds of poultry
Identification of various breeds of poultry
mithu mehr
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
eShikshak
 
Hatchery Management
Hatchery ManagementHatchery Management
Hatchery Management
Osama Zahid
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
Terry Yoast
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Marc Steel
 

Tendances (20)

Identification of various breeds of poultry
Identification of various breeds of poultryIdentification of various breeds of poultry
Identification of various breeds of poultry
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
Indian Fishing Industry
Indian Fishing IndustryIndian Fishing Industry
Indian Fishing Industry
 
Introduction to aquaculture
Introduction to aquacultureIntroduction to aquaculture
Introduction to aquaculture
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
Fish scale ornaments
Fish scale ornamentsFish scale ornaments
Fish scale ornaments
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Css lists
Css listsCss lists
Css lists
 
Hatchery Management
Hatchery ManagementHatchery Management
Hatchery Management
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Oyster aquaculture production
Oyster aquaculture productionOyster aquaculture production
Oyster aquaculture production
 
Лекции и задания по рнр
Лекции и задания по рнрЛекции и задания по рнр
Лекции и задания по рнр
 
Environmental factors affecting life in the oceans oxygen & carbon dioxide
Environmental factors affecting life in the oceans oxygen & carbon dioxideEnvironmental factors affecting life in the oceans oxygen & carbon dioxide
Environmental factors affecting life in the oceans oxygen & carbon dioxide
 
EXPONENTIAL DACAY MODEL & MORTALITY CONCEPT IN FISH STOCK ASSESSMENT
EXPONENTIAL DACAY MODEL & MORTALITY CONCEPT IN FISH STOCK ASSESSMENTEXPONENTIAL DACAY MODEL & MORTALITY CONCEPT IN FISH STOCK ASSESSMENT
EXPONENTIAL DACAY MODEL & MORTALITY CONCEPT IN FISH STOCK ASSESSMENT
 
Chapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsChapter 13: Colors and Backgrounds
Chapter 13: Colors and Backgrounds
 
Formatting tags
Formatting tagsFormatting tags
Formatting tags
 
HTML and CSS.pptx
HTML and CSS.pptxHTML and CSS.pptx
HTML and CSS.pptx
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 

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
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
<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
 
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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Prototype & jQuery