This talk recaps some features and practices that are best to avoid in good jQuery pages and apps. Following these rules will improve performance and maintainability, and may prevent your co-workers from coming after you with sharp objects.
4. 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."
48. $("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";
});
50. $(".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;
}
}