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)
• "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>
• $.browser 
• $(elements).live( … )
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
console.time("init"); 
$("body").removeClass("activated"); 
$("p.showing").css("color", "blue"); 
console.timeEnd("init");
8 ms
:visible :hidden 
data- .data()
• $("#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
$.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()
$("#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();

jQuery Foot-Gun Features