jQuery 1.3.2 has been released, bringing a round of welcome performance improvements and bug fixes to the most popular JavaScript library in the world.
What's New in jQuery 1.3.2
The headline addition is the integration of the Sizzle CSS selector engine. Sizzle is a standalone, high-performance CSS selector engine that replaces jQuery's previous selector implementation. The results are dramatic: selector performance is up to 4x faster in some cases, particularly for complex CSS3 selectors and large documents.
The .live() event method has also been made significantly more robust. Introduced in jQuery 1.3, .live() enables event delegation — you attach an event handler once to a parent element (or document), and it fires for any matching descendant, even ones added to the DOM after the handler was bound. This is essential when working with dynamically generated content.
Summary of notable changes in the 1.3.x series:
- Sizzle selector engine integrated — dramatic speed improvements for complex selectors
.live()event delegation — handle events on dynamically added elements- Selector engine up to 4x faster compared to 1.2.x in benchmark tests
- Numerous bug fixes across DOM manipulation, events, and Ajax
- Reduced file size despite the new features
Event Delegation with .live()
The introduction of .live() in 1.3 changed how many developers handle dynamic content. Instead of rebinding events every time you add new elements, you can write:
// Old approach — must be re-run whenever new .item elements are added
$('.item').click(function() { ... });
// New approach with .live() — works for all .item elements, present and future
$('.item').live('click', function() { ... });
This is especially useful for content loaded via Ajax or elements created in response to user actions.
Updating WordPress to jQuery 1.3.2
WordPress ships with its own bundled version of jQuery, which may lag behind the latest release. To use jQuery 1.3.2 in your WordPress theme or plugin, you have two options:
Option 1 — Replace via functions.php:
function mytheme_scripts() {
wp_deregister_script('jquery');
wp_register_script('jquery',
'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
false, '1.3.2');
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'mytheme_scripts');
Option 2 — Use wp_enqueue_script properly:
// In functions.php — the correct way to load jQuery in WordPress
function mytheme_scripts() {
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'mytheme_scripts');
Note that WordPress loads jQuery in noConflict mode by default, meaning the $ shorthand is not available globally. Use jQuery instead, or wrap your code in a self-executing function:
(function($) {
// Safe to use $ here
$(document).ready(function() {
// your code
});
})(jQuery);
jQuery 1.3.2 is a recommended update for all projects. The performance gains from Sizzle alone make it worthwhile.