SlideShare a Scribd company logo
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
Let's make standards work 
for us, solving real problems! 
Web developer needs should 
be expressed early in the 
process, before a standard is 
deployed in browsers and it 
becomes "too late to fix it."
(builtwith.com)
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
• "Please code responsibly"
jquery-latest.js 
download 
http://code.jquery.com/jquery-latest.js 
http://code.jquery.com/jquery-latest.min.js 
<script src="http://code.jquery.com/jquery-latest. 
js"></script>
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
jQuery Foot-Gun Features
• $.browser 
• $(elements).live( … )
jQuery Foot-Gun Features
From High Performance Browser Networking by Ilya Grigorik (O'Reilly)
:visible :hidden 
console.time("init"); 
$("body").removeClass("activated"); 
$("p:visible").css("color", "blue"); 
console.timeEnd("init");
30 ms
jQuery Foot-Gun Features
console.time("init"); 
$("body").removeClass("activated"); 
$("p.showing").css("color", "blue"); 
console.timeEnd("init");
8 ms
:visible :hidden 
data- .data()
jQuery Foot-Gun Features
• $("#abc").show() 
• $("#abc").hide() 
style 
What could possibly go wrong?
$("<span>Hi!</span>") 
.show() 
.appendTo("body");
<style> 
span { display: none; } 
</style> 
$("<span>Hi!</span>") 
.show() 
.appendTo("body");
<style> 
span { display: block; } 
</style> 
$("<span>Hi!</span>") 
.show() 
.appendTo("body");
<style> 
@media screen and (max-width: 700px) { 
#bar { display: none; } 
} 
</style> 
$("#bar").show();
display
jQuery Foot-Gun Features
$.ajax({ 
url: "file.txt", 
success: function(data){ 
alert(data); 
} 
});
$.ajaxSetup({ 
type: "POST", 
dataType: "json", 
timeout: 500 // ms! 
});
BAD 
$.ajaxSetup()
function remoteCommand(options) 
{ 
return $.ajax( 
$.extend({ 
dataType: "json", 
timeout: 1000, 
... 
}, options) 
); 
}
• $(function) 
• $(domelement) 
• $([ domelement, domelement … ]) 
• $({ name: value, … }) 
• $("htmlelement", { attribute: value }) 
• $("selector") 
• $("html")
$(selector).appendTo("body"); 
var selector = "<script>alert(42)</script>";
.text()
jQuery Foot-Gun Features
jQuery Foot-Gun Features
$("#toggle-checkboxes").on("click", function( event ) { 
$(".cb").each(function() { 
$(this).prop("checked", !$(this).prop("checked")); 
}); 
});
$("#toggle-checkboxes").on("click", function( event ) { 
$(".cb").each(function() { 
this.checked = !this.checked; 
}); 
});
Instead of $(this) … Use this! 
$(this).is(“:checked”) this.checked 
$(this).prop(“checked”) this.checked 
$(this).is(“:disabled”) this.disabled 
$(this).attr(“id”) this.id 
$(this).attr(“class”) this.className
querySelectorAll
:checkbox, :radio, :text, :image, 
:file, :reset 
input[type=X] 
:button button, input[type=button] 
:header h1, h2, h3, h4, h5 
:first :first-child or .first() 
:last :last-child or .last()
$("div").on("click", function( event ) { 
// Throws an error in IE8 or the Android 2.x browser 
this.className.add("clicked"); 
// Works everywhere 
$(this).addClass("clicked"); 
// Works everywhere if you can clobber className 
this.className = "clicked"; 
});
Twitter: @davemethvin 
Github: dmethvin 
Email: dave.methvin@gmail.com
$(".msg").addClass("unread"); 
compared to 
var unreadClass = "unread", 
msgs = document.getElementsByClassName("msg"); 
var cls = new RegExp("b"+unreadClass+"b"); 
for ( var i=0; i < msgs.length; i++ ) { 
if ( !cls.test(msgs[i]) { 
msgs[i].className += " "+unreadClass; 
} 
}
jQuery.fn.makeBlue = function() { 
return this.css("color", "blue"); 
} 
$(".da-ba-de-da-ba-di").makeBlue();

More Related Content

What's hot (20)

KEY
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PDF
jQuery
Andrew Homeyer
 
PPTX
Knockoutjs UG meeting presentation
Valdis Iljuconoks
 
PPTX
AngularJS Routing
Eyal Vardi
 
PDF
A re introduction to webpack - reactfoo - mumbai
Praveen Puglia
 
PDF
Processing and Processing.js
jeresig
 
PDF
Front-End Developers Can Makes Games, Too!
FITC
 
PDF
Build web application by express
Shawn Meng
 
KEY
Extjs + Gears
hagino 3000
 
PDF
Drupal, meet Assetic
Kris Wallsmith
 
PDF
WordPress-Powered Portfolios
Tyler Sticka
 
PDF
Casl. isomorphic permission management.pptx
Sergiy Stotskiy
 
PDF
Shibuya.js Lightning Talks
jeresig
 
PDF
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
PPTX
AngularJS $Provide Service
Eyal Vardi
 
PDF
jQuery Essentials
Bedis ElAchèche
 
PPTX
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
PDF
React.js触ってみた 吉澤和香奈
Wakana Yoshizawa
 
PPTX
Auto tools
祺 周
 
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
Knockoutjs UG meeting presentation
Valdis Iljuconoks
 
AngularJS Routing
Eyal Vardi
 
A re introduction to webpack - reactfoo - mumbai
Praveen Puglia
 
Processing and Processing.js
jeresig
 
Front-End Developers Can Makes Games, Too!
FITC
 
Build web application by express
Shawn Meng
 
Extjs + Gears
hagino 3000
 
Drupal, meet Assetic
Kris Wallsmith
 
WordPress-Powered Portfolios
Tyler Sticka
 
Casl. isomorphic permission management.pptx
Sergiy Stotskiy
 
Shibuya.js Lightning Talks
jeresig
 
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
AngularJS $Provide Service
Eyal Vardi
 
jQuery Essentials
Bedis ElAchèche
 
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
React.js触ってみた 吉澤和香奈
Wakana Yoshizawa
 
Auto tools
祺 周
 

Viewers also liked (8)

PPTX
jQuery Conference Chicago - September 2014
dmethvin
 
PDF
PrairieDevCon 2014 - Web Doesn't Mean Slow
dmethvin
 
PDF
jQuery Conference Toronto
dmethvin
 
PPTX
HTTP 2.0 - Web Unleashed 2015
dmethvin
 
PDF
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
PDF
jQueryTO: State of jQuery March 2013
dmethvin
 
PDF
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Dan Gribbin
 
PPT
State of jQuery - AspDotNetStorefront Conference
dmethvin
 
jQuery Conference Chicago - September 2014
dmethvin
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
dmethvin
 
jQuery Conference Toronto
dmethvin
 
HTTP 2.0 - Web Unleashed 2015
dmethvin
 
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
jQueryTO: State of jQuery March 2013
dmethvin
 
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Dan Gribbin
 
State of jQuery - AspDotNetStorefront Conference
dmethvin
 
Ad

Similar to jQuery Foot-Gun Features (20)

PDF
Jquery In Rails
shen liu
 
PDF
jQuery
Ivano Malavolta
 
KEY
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 
PDF
jQuery UI and Plugins
Marc Grabanski
 
PPT
J query
Manav Prasad
 
PPTX
Javascript first-class citizenery
toddbr
 
PDF
jQuery Rescue Adventure
Allegient
 
PDF
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
PDF
Cheap frontend tricks
ambiescent
 
PDF
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
PPTX
Unobtrusive javascript with jQuery
Angel Ruiz
 
PPTX
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
PDF
Introduzione JQuery
orestJump
 
PPT
Kick start with j query
Md. Ziaul Haq
 
PPTX
jQuery
Dileep Mishra
 
PDF
jQuery Essentials
Marc Grabanski
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PDF
前端MVC 豆瓣说
Ting Lv
 
PDF
Jquery presentation
Mevin Mohan
 
Jquery In Rails
shen liu
 
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 
jQuery UI and Plugins
Marc Grabanski
 
J query
Manav Prasad
 
Javascript first-class citizenery
toddbr
 
jQuery Rescue Adventure
Allegient
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
Cheap frontend tricks
ambiescent
 
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Unobtrusive javascript with jQuery
Angel Ruiz
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
 
Introduzione JQuery
orestJump
 
Kick start with j query
Md. Ziaul Haq
 
jQuery Essentials
Marc Grabanski
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
前端MVC 豆瓣说
Ting Lv
 
Jquery presentation
Mevin Mohan
 
Ad

Recently uploaded (20)

PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Python basic programing language for automation
DanialHabibi2
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

jQuery Foot-Gun Features