(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
intro to jQuery
Rafael Gonzaque
Startup Institute NY
December 4, 2015
hi there!
Rafael Gonzaque
Software Engineer @
Maple
@iamrgon
I like lobster rolls and
running.
what is
?
Delicious meals made by some of the best chefs in
the city, delivered in 30 minutes.
Thoughtfully sourced, balanced meals that rotate
daily all wrapped in a reliable experience and at an
accessible price ($12 for lunch and $15 for dinner -
tax, tip and delivery included).
try something new everyday
delivered in 30 minutes or less
currently serving all of Manhattan below
14th st
ios, android, and all modern browsers
we write a ton of
javascript
• handling events
• submitting and fetching data
• rendering content
• serving web pages
• query databases
to do things like …
today,we’ll focus
on the browser
accessing
the DOM to
you’ll spend most of your time
bind events
read form values
modify html
render content
the DOM? huh?!
DOM = document object model
A programming interface for HTML, XML and SVG
documents. It provides a structured representation of
the document (a tree) and it defines a way that the
structure can be accessed from programs so that they
can change the document structure, style and content.
learn more: https://developer.mozilla.org/en-US/docs/Web/API/
Document_Object_Model
tree structure
how do you
access the DOM?
// document is a global variable
var el = document.getElementById(“some id attribute”);
var elems = document.getElementsByTagName(“P”);
var myNewEl = document.createElement(“DIV”);
three core methods
learn more: https://developer.mozilla.org/en-US/docs/Web/API/
Document_Object_Model/Introduction
example
we’re web developers at the hot, new todo list
startup, ToDo-odles.
let’s write the html for viewing a todo list.
<html>
<body>
<h1 id=“title”>ToDo-odles – To-do lists for days!</h1>
<div class=“content”>
<p>Rafael’s Monday To-Dos</p>
<ul id=“task-list” class=“list”>
<li class=“item”>
<span class=“item-title”>Pickup laundry</span>
<span class=“item-desc”>At the corner laundromat</span>
</li>
</ul>
<a id=“new-btn” href=“#” class=“btn”>New</a>
</div>
</body>
</html>
html
// Find the New button
var addNewBtn = document.getElementById(“new-btn”);
// Listen to click events on the New button
addNewBtn.addEventListener(“click”, function () {
alert(“Clicked the New button”);
// do something else
});
let’s make this interactive
oh no!
x-browser issues
Until IE 9, IE didn’t implement addEventListener; it
had its own – attachEvent
Solution:
function onClickHandler() {
alert(“Clicked the New button”);
}
var addNewBtn = document.getElementById(“new-btn”);
if (IE < 9 /* Pseudo-code for < IE 9 check */) {
addNewBtn.attachEvent(“click”, onClickHandler);
} else {
addNewBtn.addEventListener(“click”, onClickHandler);
}
other x-browser issues across vendors
• varying support for HTML5 features
• missing api methods like,
• distinct rendering and positioning content
• two different ways to make ajax calls
Array.prototype.forEach
enter
about jQuery
• makes web development easier
• written by John Resig in 2006
• 65.5% of Quantcast Top 10k sites
learn more: http://trends.builtwith.com/javascript/jQuery
some sites that use jQuery
airbnb
foursquare
tumblr
genius
why use jQuery?
• a common interface to manipulate the DOM
– the jQuery object
• css selectors for DOM queries
• plugin system
learn more: Sizzle, jQuery’s selector engine – http://sizzlejs.com/
$ ftw!
// Find all paragraph elements
var $pTags = $(“p”);
// Find all elements with class attribute “titles”
var $titles = $(“.titles”);
// Find element with id attribute “my-div”
var $myDiv = $(“#my-div”);
if ($ === jQuery) {
alert(“$ and jQuery are global and equal”);
}
back to
ToDo-odles
html
<html>
<body>
<h1 id=“title”>ToDo-odles – To-do lists for days!</h1>
<div class=“content”>
<p>Rafael’s Monday To-Dos</p>
<ul id=“task-list” class=“list”>
<li class=“item”>
<span class=“item-title”>Pickup laundry</span>
<span class=“item-desc”>At the corner laundromat</span>
</li>
</ul>
<a id=“new-btn” href=“#” class=“btn”>New</a>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</body>
</html>
interactivity with jQuery
// Change the color of the title
$(“#title”).css(“font-size”, “36pt”);
// Listen to click events on the New button
$(“#new-btn”).on(“click”, function() {
alert(“Clicked the New button”);
$(this).addClass(“inactive”);
}
notice there’s no need to check IE version; jQuery
does it internally!
more examples
// Append a new item to the list
var html = ‘<li class=“item”><span class=“item-title”>’ +
‘Get Milk</span><span class=“item-desc”>1% milkfat</span></li>’;
$(‘#task-list’).append(html);
// Remove last item in the list from the DOM
$(“#task-list”).find(“.item:last-child”).remove();
// Add class, “urgent” to the first element with class “item”
$(“.item”).eq(0).addClass(“urgent”);
submitting and
fetching data with
ajax
what is ajax?
ajax = asynchronous javascript and xml
With Ajax, web applications can send data to and
retrieve from a server asynchronously (in the
background) without interfering with the display and
behavior of the existing page.
learn more: https://en.wikipedia.org/wiki/Ajax_(programming)
why ajax?
• dynamic web pages – partial updates to page
sections without needing to reload the page
• responsive web experiences – saving and fetching
information appears to happen instantly
how?
var xhReq;
// Less than IE 7 support
if (window.ActiveXObject) {
xhReq = new ActiveXObject(“Msxml2.XMLHTTP”);
} else {
xhReq = new XmlHttpRequest();
}
// Make an async request
xhReq.open(“GET”, “my-app-endpoint?id=2”);
xhReq.onreadystatechange = function() {
// We only care about complete requests (state = 4)
if (xhReq.readyState != 4) { return; }
if (xhReq.status != 200) {
// Handle error
} else {
// Handle success via xhReq.responseText
}
};
xhReq.send(null);
now with
ajax with jQuery
learn more: full jQuery documentation – http://api.jquery.com/
// No need to deal with XMLHttpRequest to do AJAX
// jQuery does AJAX!
$.ajax({
url: “/my-app-endpoint”,
type: “GET”,
data: { id: 2 },
success: function (response) {
// Handle the response
},
error: function () {
// Handle the error
}
});
best practices
// Prefix all variables that reference a jQuery object with
a “$”
var $taskList = $(“#task-list”);
// A jQuery object is array-like; check the length to see
if an element exist
var $someElement = $(“#parent .non-existing-selector”);
console.log($taskList.length); // 1
console.log($someElement.length); // 0
more best practices
// jQuery objects are chain-able
$(“#title”)
.addClass(“crucial”)
.text(“Pay Attention”)
.on(“click”, function () { /* Do something*/ });
// Use event delegation to bind events to multiple instances of
the same html markup
$(“#task-list”).on(“click”, “.item”, function () {
// Do something when a .item element is clicked
});
always prefer css over javascript; css is much faster
other dom libraries
zepto.js
learn more: http://zeptojs.com/
• smaller in size than jQuery
• the same api (methods) as jQuery
• no support for IE 9 and below
prototype.js
learn more: http://prototypejs.org/
• really stable – 1.7 release since Nov 2010
• extends native DOM – adds methods to
Element
• id DOM search like
• css DOM search like
Element
$(“id-attribute”)
$$(“p.title”)
some others …
• YUI – https://yuilibrary.com/
• Dojo – http://dojotoolkit.org/
• MooTools – http://mootools.net/
now trending:
component-based
single page applications
single page apps
Single-Page Applications (SPAs) are Web apps that
load a single HTML page and dynamically update
that page as the user interacts with the app.
SPAs use AJAX and HTML5 to create fluid and
responsive Web apps, without constant page
reloads. However, this means much of the work
happens on the client side, in JavaScript.
learn more: https://en.wikipedia.org/wiki/Single-page_application
component-based development
Component-based development is a software
design pattern where view logic (how
interactions are controlled) are fully
encapsulated in a component or widget.
The strategy leads to better maintainability
and greater code re-use.
component-based SPA frameworks
Flight
(Twitter)
React
(Facebook)
Angular
(Google)
Open-Source
(Community!)
jQuery is completely optional
with the exception of Flight (which uses
jQuery), the SPA frameworks don’t require you
to use any additional libraries.
on the component level, you always have
access to the DOM nodes so, you rarely need
to traverse the DOM tree from the root node.
react example
var Avatar = React.createClass({
render: function() {
return (
<div>
<ProfilePic username={this.props.username} />
</div>
);
}
});
var ProfilePic = React.createClass({
render: function() {
return (
<img src={'https://graph.facebook.com/' + this.props.username + '/picture'} />
);
}
});
React.render(
<Avatar username=“rafael.gonzaque" />,
document.getElementById('app')
);
wrap up
jQuery summary
• provides x-browser functionality for DOM manipulation and ajax
• makes web development easier
• always, prefer css solutions over javascript with jQuery
• exposes a common interface that make plugins possible. See:
1. http://plugins.jquery.com/
2. http://www.unheap.com/
3. http://learn.jquery.com/plugins/basic-plugin-creation/
thanks!
@iamrgon on Twitter for questions/comments

More Related Content

What's hot

Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
Laurence Svekis ✔
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
Arwid Bancewicz
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
Ravi Raj
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
Jussi Pohjolainen
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
Andrew Rota
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web Components
Michiel De Mey
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
Tomi Juhola
 
jQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and FuturejQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and Future
Richard Worth
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
Zachary Klein
 
handout-05b
handout-05bhandout-05b
handout-05b
tutorialsruby
 
Javascript, DOM, browsers and frameworks basics
Javascript, DOM, browsers and frameworks basicsJavascript, DOM, browsers and frameworks basics
Javascript, DOM, browsers and frameworks basics
Net7
 
Ajax3
Ajax3Ajax3
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
Anil Kumar
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
Brian Moschel
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
Yorick Phoenix
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
colinbdclark
 

What's hot (19)

Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web Components
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
jQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and FuturejQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and Future
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
 
handout-05b
handout-05bhandout-05b
handout-05b
 
Javascript, DOM, browsers and frameworks basics
Javascript, DOM, browsers and frameworks basicsJavascript, DOM, browsers and frameworks basics
Javascript, DOM, browsers and frameworks basics
 
Ajax3
Ajax3Ajax3
Ajax3
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 

Similar to Intro to jQuery @ Startup Institute

Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
Catherine Beltran
 
Ajax
AjaxAjax
Html5
Html5Html5
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
Mark Roden
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
WebStackAcademy
 
Projects In JavaScript And JQuery | Eduonix
Projects In JavaScript And JQuery | EduonixProjects In JavaScript And JQuery | Eduonix
Projects In JavaScript And JQuery | Eduonix
Rakhi Lambha
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
William Myers
 
Building intranet applications with ASP.NET AJAX and jQuery
Building intranet applications with ASP.NET AJAX and jQueryBuilding intranet applications with ASP.NET AJAX and jQuery
Building intranet applications with ASP.NET AJAX and jQuery
Alek Davis
 
Progressive Web Apps and React
Progressive Web Apps and ReactProgressive Web Apps and React
Progressive Web Apps and React
Mike Melusky
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
Syed Moosa Kaleem
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
Simon Willison
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 Apps
Marcos Caceres
 
What is HTML 5?
What is HTML 5?What is HTML 5?
What is HTML 5?
Susan Winters
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
AppUniverz Org
 
jQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesjQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPages
Teamstudio
 
React + Flux = Joy
React + Flux = JoyReact + Flux = Joy
React + Flux = Joy
John Need
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
tutorialsruby
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
tutorialsruby
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
Gurpreet singh
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
Jesús L. Domínguez Muriel
 

Similar to Intro to jQuery @ Startup Institute (20)

Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Ajax
AjaxAjax
Ajax
 
Html5
Html5Html5
Html5
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
 
Projects In JavaScript And JQuery | Eduonix
Projects In JavaScript And JQuery | EduonixProjects In JavaScript And JQuery | Eduonix
Projects In JavaScript And JQuery | Eduonix
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
Building intranet applications with ASP.NET AJAX and jQuery
Building intranet applications with ASP.NET AJAX and jQueryBuilding intranet applications with ASP.NET AJAX and jQuery
Building intranet applications with ASP.NET AJAX and jQuery
 
Progressive Web Apps and React
Progressive Web Apps and ReactProgressive Web Apps and React
Progressive Web Apps and React
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 Apps
 
What is HTML 5?
What is HTML 5?What is HTML 5?
What is HTML 5?
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
jQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesjQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPages
 
React + Flux = Joy
React + Flux = JoyReact + Flux = Joy
React + Flux = Joy
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 

Recently uploaded

Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
DianaGray10
 
Chapter 1 - Fundamentals of Testing V4.0
Chapter 1 - Fundamentals of Testing V4.0Chapter 1 - Fundamentals of Testing V4.0
Chapter 1 - Fundamentals of Testing V4.0
Neeraj Kumar Singh
 
Cassandra to ScyllaDB: Technical Comparison and the Path to Success
Cassandra to ScyllaDB: Technical Comparison and the Path to SuccessCassandra to ScyllaDB: Technical Comparison and the Path to Success
Cassandra to ScyllaDB: Technical Comparison and the Path to Success
ScyllaDB
 
Supplier Sourcing Presentation - Gay De La Cruz.pdf
Supplier Sourcing Presentation - Gay De La Cruz.pdfSupplier Sourcing Presentation - Gay De La Cruz.pdf
Supplier Sourcing Presentation - Gay De La Cruz.pdf
gaydlc2513
 
Cyber Recovery Wargame
Cyber Recovery WargameCyber Recovery Wargame
Cyber Recovery Wargame
Databarracks
 
Getting Started Using the National Research Platform
Getting Started Using the National Research PlatformGetting Started Using the National Research Platform
Getting Started Using the National Research Platform
Larry Smarr
 
From NCSA to the National Research Platform
From NCSA to the National Research PlatformFrom NCSA to the National Research Platform
From NCSA to the National Research Platform
Larry Smarr
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
dipikamodels1
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
Kieran Kunhya
 
Corporate Open Source Anti-Patterns: A Decade Later
Corporate Open Source Anti-Patterns: A Decade LaterCorporate Open Source Anti-Patterns: A Decade Later
Corporate Open Source Anti-Patterns: A Decade Later
ScyllaDB
 
Move Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the PlatformMove Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the Platform
Christian Posta
 
Chapter 3 - Static Testing (Review) V4.0
Chapter 3 - Static Testing (Review) V4.0Chapter 3 - Static Testing (Review) V4.0
Chapter 3 - Static Testing (Review) V4.0
Neeraj Kumar Singh
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
manji sharman06
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
anilsa9823
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
Overkill Security
 
intra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_Enintra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_En
NTTDATA INTRAMART
 
Leveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptxLeveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptx
petabridge
 
Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0
Neeraj Kumar Singh
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
UiPathCommunity
 

Recently uploaded (20)

Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
 
Chapter 1 - Fundamentals of Testing V4.0
Chapter 1 - Fundamentals of Testing V4.0Chapter 1 - Fundamentals of Testing V4.0
Chapter 1 - Fundamentals of Testing V4.0
 
Cassandra to ScyllaDB: Technical Comparison and the Path to Success
Cassandra to ScyllaDB: Technical Comparison and the Path to SuccessCassandra to ScyllaDB: Technical Comparison and the Path to Success
Cassandra to ScyllaDB: Technical Comparison and the Path to Success
 
Supplier Sourcing Presentation - Gay De La Cruz.pdf
Supplier Sourcing Presentation - Gay De La Cruz.pdfSupplier Sourcing Presentation - Gay De La Cruz.pdf
Supplier Sourcing Presentation - Gay De La Cruz.pdf
 
Cyber Recovery Wargame
Cyber Recovery WargameCyber Recovery Wargame
Cyber Recovery Wargame
 
Getting Started Using the National Research Platform
Getting Started Using the National Research PlatformGetting Started Using the National Research Platform
Getting Started Using the National Research Platform
 
From NCSA to the National Research Platform
From NCSA to the National Research PlatformFrom NCSA to the National Research Platform
From NCSA to the National Research Platform
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
 
Corporate Open Source Anti-Patterns: A Decade Later
Corporate Open Source Anti-Patterns: A Decade LaterCorporate Open Source Anti-Patterns: A Decade Later
Corporate Open Source Anti-Patterns: A Decade Later
 
Move Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the PlatformMove Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the Platform
 
Chapter 3 - Static Testing (Review) V4.0
Chapter 3 - Static Testing (Review) V4.0Chapter 3 - Static Testing (Review) V4.0
Chapter 3 - Static Testing (Review) V4.0
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
 
intra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_Enintra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_En
 
Leveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptxLeveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptx
 
Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
 

Intro to jQuery @ Startup Institute

  • 1. intro to jQuery Rafael Gonzaque Startup Institute NY December 4, 2015
  • 2. hi there! Rafael Gonzaque Software Engineer @ Maple @iamrgon I like lobster rolls and running.
  • 4. Delicious meals made by some of the best chefs in the city, delivered in 30 minutes. Thoughtfully sourced, balanced meals that rotate daily all wrapped in a reliable experience and at an accessible price ($12 for lunch and $15 for dinner - tax, tip and delivery included).
  • 5. try something new everyday
  • 6. delivered in 30 minutes or less
  • 7. currently serving all of Manhattan below 14th st ios, android, and all modern browsers
  • 8. we write a ton of javascript
  • 9. • handling events • submitting and fetching data • rendering content • serving web pages • query databases to do things like …
  • 11. accessing the DOM to you’ll spend most of your time bind events read form values modify html render content
  • 12. the DOM? huh?! DOM = document object model A programming interface for HTML, XML and SVG documents. It provides a structured representation of the document (a tree) and it defines a way that the structure can be accessed from programs so that they can change the document structure, style and content. learn more: https://developer.mozilla.org/en-US/docs/Web/API/ Document_Object_Model
  • 14. how do you access the DOM?
  • 15. // document is a global variable var el = document.getElementById(“some id attribute”); var elems = document.getElementsByTagName(“P”); var myNewEl = document.createElement(“DIV”); three core methods learn more: https://developer.mozilla.org/en-US/docs/Web/API/ Document_Object_Model/Introduction
  • 16. example we’re web developers at the hot, new todo list startup, ToDo-odles. let’s write the html for viewing a todo list.
  • 17. <html> <body> <h1 id=“title”>ToDo-odles – To-do lists for days!</h1> <div class=“content”> <p>Rafael’s Monday To-Dos</p> <ul id=“task-list” class=“list”> <li class=“item”> <span class=“item-title”>Pickup laundry</span> <span class=“item-desc”>At the corner laundromat</span> </li> </ul> <a id=“new-btn” href=“#” class=“btn”>New</a> </div> </body> </html> html
  • 18. // Find the New button var addNewBtn = document.getElementById(“new-btn”); // Listen to click events on the New button addNewBtn.addEventListener(“click”, function () { alert(“Clicked the New button”); // do something else }); let’s make this interactive
  • 20. x-browser issues Until IE 9, IE didn’t implement addEventListener; it had its own – attachEvent Solution: function onClickHandler() { alert(“Clicked the New button”); } var addNewBtn = document.getElementById(“new-btn”); if (IE < 9 /* Pseudo-code for < IE 9 check */) { addNewBtn.attachEvent(“click”, onClickHandler); } else { addNewBtn.addEventListener(“click”, onClickHandler); }
  • 21. other x-browser issues across vendors • varying support for HTML5 features • missing api methods like, • distinct rendering and positioning content • two different ways to make ajax calls Array.prototype.forEach
  • 22. enter
  • 23. about jQuery • makes web development easier • written by John Resig in 2006 • 65.5% of Quantcast Top 10k sites learn more: http://trends.builtwith.com/javascript/jQuery
  • 24. some sites that use jQuery airbnb foursquare tumblr genius
  • 25. why use jQuery? • a common interface to manipulate the DOM – the jQuery object • css selectors for DOM queries • plugin system learn more: Sizzle, jQuery’s selector engine – http://sizzlejs.com/
  • 26. $ ftw! // Find all paragraph elements var $pTags = $(“p”); // Find all elements with class attribute “titles” var $titles = $(“.titles”); // Find element with id attribute “my-div” var $myDiv = $(“#my-div”); if ($ === jQuery) { alert(“$ and jQuery are global and equal”); }
  • 28. html <html> <body> <h1 id=“title”>ToDo-odles – To-do lists for days!</h1> <div class=“content”> <p>Rafael’s Monday To-Dos</p> <ul id=“task-list” class=“list”> <li class=“item”> <span class=“item-title”>Pickup laundry</span> <span class=“item-desc”>At the corner laundromat</span> </li> </ul> <a id=“new-btn” href=“#” class=“btn”>New</a> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </body> </html>
  • 29. interactivity with jQuery // Change the color of the title $(“#title”).css(“font-size”, “36pt”); // Listen to click events on the New button $(“#new-btn”).on(“click”, function() { alert(“Clicked the New button”); $(this).addClass(“inactive”); } notice there’s no need to check IE version; jQuery does it internally!
  • 30. more examples // Append a new item to the list var html = ‘<li class=“item”><span class=“item-title”>’ + ‘Get Milk</span><span class=“item-desc”>1% milkfat</span></li>’; $(‘#task-list’).append(html); // Remove last item in the list from the DOM $(“#task-list”).find(“.item:last-child”).remove(); // Add class, “urgent” to the first element with class “item” $(“.item”).eq(0).addClass(“urgent”);
  • 32. what is ajax? ajax = asynchronous javascript and xml With Ajax, web applications can send data to and retrieve from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. learn more: https://en.wikipedia.org/wiki/Ajax_(programming)
  • 33. why ajax? • dynamic web pages – partial updates to page sections without needing to reload the page • responsive web experiences – saving and fetching information appears to happen instantly
  • 34. how? var xhReq; // Less than IE 7 support if (window.ActiveXObject) { xhReq = new ActiveXObject(“Msxml2.XMLHTTP”); } else { xhReq = new XmlHttpRequest(); } // Make an async request xhReq.open(“GET”, “my-app-endpoint?id=2”); xhReq.onreadystatechange = function() { // We only care about complete requests (state = 4) if (xhReq.readyState != 4) { return; } if (xhReq.status != 200) { // Handle error } else { // Handle success via xhReq.responseText } }; xhReq.send(null);
  • 36. ajax with jQuery learn more: full jQuery documentation – http://api.jquery.com/ // No need to deal with XMLHttpRequest to do AJAX // jQuery does AJAX! $.ajax({ url: “/my-app-endpoint”, type: “GET”, data: { id: 2 }, success: function (response) { // Handle the response }, error: function () { // Handle the error } });
  • 37. best practices // Prefix all variables that reference a jQuery object with a “$” var $taskList = $(“#task-list”); // A jQuery object is array-like; check the length to see if an element exist var $someElement = $(“#parent .non-existing-selector”); console.log($taskList.length); // 1 console.log($someElement.length); // 0
  • 38. more best practices // jQuery objects are chain-able $(“#title”) .addClass(“crucial”) .text(“Pay Attention”) .on(“click”, function () { /* Do something*/ }); // Use event delegation to bind events to multiple instances of the same html markup $(“#task-list”).on(“click”, “.item”, function () { // Do something when a .item element is clicked }); always prefer css over javascript; css is much faster
  • 40. zepto.js learn more: http://zeptojs.com/ • smaller in size than jQuery • the same api (methods) as jQuery • no support for IE 9 and below
  • 41. prototype.js learn more: http://prototypejs.org/ • really stable – 1.7 release since Nov 2010 • extends native DOM – adds methods to Element • id DOM search like • css DOM search like Element $(“id-attribute”) $$(“p.title”)
  • 42. some others … • YUI – https://yuilibrary.com/ • Dojo – http://dojotoolkit.org/ • MooTools – http://mootools.net/
  • 44. single page apps Single-Page Applications (SPAs) are Web apps that load a single HTML page and dynamically update that page as the user interacts with the app. SPAs use AJAX and HTML5 to create fluid and responsive Web apps, without constant page reloads. However, this means much of the work happens on the client side, in JavaScript. learn more: https://en.wikipedia.org/wiki/Single-page_application
  • 45. component-based development Component-based development is a software design pattern where view logic (how interactions are controlled) are fully encapsulated in a component or widget. The strategy leads to better maintainability and greater code re-use.
  • 47. jQuery is completely optional with the exception of Flight (which uses jQuery), the SPA frameworks don’t require you to use any additional libraries. on the component level, you always have access to the DOM nodes so, you rarely need to traverse the DOM tree from the root node.
  • 48. react example var Avatar = React.createClass({ render: function() { return ( <div> <ProfilePic username={this.props.username} /> </div> ); } }); var ProfilePic = React.createClass({ render: function() { return ( <img src={'https://graph.facebook.com/' + this.props.username + '/picture'} /> ); } }); React.render( <Avatar username=“rafael.gonzaque" />, document.getElementById('app') );
  • 50. jQuery summary • provides x-browser functionality for DOM manipulation and ajax • makes web development easier • always, prefer css solutions over javascript with jQuery • exposes a common interface that make plugins possible. See: 1. http://plugins.jquery.com/ 2. http://www.unheap.com/ 3. http://learn.jquery.com/plugins/basic-plugin-creation/
  • 51. thanks! @iamrgon on Twitter for questions/comments