The third minor release of jQuery 1.4 is available now. The popular JavaScript library has received a number of additional methods, bug fixes and speed improvements — here are the new features which caught my eye…
jQuery.type
Determining type can be tricky in JavaScript. Everything is an object so you need to be especially careful with the standard typeof function. jQuery.type will make life much easier for developers…
$.type(true) === "boolean"
$.type(3) === "number"
$.type("test") === "string"
$.type(function(){}) === "function"
$.type([]) === "array"
$.type(new Date()) === "date"
$.type(/test/) === "regexp"
HTML5 data attributes
jQuery now supports HTML5 data attributes, e.g.
<div id="info" data-site="SitePoint" data-registered="true" data-options="{'name':'user'}" />
jQuery converts values to their native JavaScript type so data can be accessed and updated, e.g.
$("#info").data("site") === "SitePoint";
$("#info").data("registered") === true;
$("#info").data("options").name === "user";
Ajax
jQuery.support.ajax is a new property which returns true in browsers which support XMLHttpRequest. This is rarely a problem on the desktop, but XHR availability is more patchy on mobile devices.
The jQuery.readyWait property has also been added. This delays execution of the ready event so you can load dependencies or perform other actions before it’s fired.
Events
It’s now possible to prevent the default action and bubbling on any element using:
$("a#link").bind("click", false);
Similarly, .unbind(“click”, false) will remove the action.
Animation and effects
The new jQuery.fx.interval property sets or gets the animation frame rate. The default is 13 milliseconds but it’s possible to reduce that value for smoother animations (assuming your browser is able to keep up).
DOM traversal
jQuery makes greater use of the native querySelectorAll and matchesSelector methods when they’re available. Some functions are now 8x faster than version 1.4.2.
CSS module
The CSS module has been rewritten so it’s possible to write custom plugins which extend .css() and .animate().
Links
Grab jQuery 1.4.3 from:
- Uncompressed version (179kB) – https://code.jquery.com/jquery-1.4.3.js
- Minified version (26kB) – https://code.jquery.com/jquery-1.4.3.min.js
- Google CDN – https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js
- jQuery 1.4.3 documentation – http://api.jquery.com/category/version/1.4.3/
Impressively, jQuery maintains good backward compatibility. The core API is stable and unlikely to break your existing applications. John Resig’s team keep polishing their code to make it faster, leaner and more flexible.
News just in …
jQuery Mobile 1.0 Alpha 1 has been released! Keep reading SitePoint for more information soon…
Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.