Registration for the jQuery Conference 2010: San Francisco Bay Area is now open!
The conference schedule and list of speakers are available on the website.
The jQuery Project is excited to announce that Microsoft is expanding its support of the jQuery JavaScript Library through new initiatives, to include code contributions, product integration, and the allocation of additional resources.
Building on two years of collaboration with the jQuery Project, Microsoft announced today at MIX 2010 that it will be working with the jQuery Core Team and community to provide source code that will help to further advance the jQuery JavaScript Library. The planned contributions target specific functionalities in areas of mutual interest. They include:
The initial focus will be on a new templating engine that will allow for easy and flexible data rendering via defined templates. Microsoft has submitted a proposal for public review along with an experimental plugin, and is actively collaborating with the jQuery team and community on a unified implementation. The templating engine will be reviewed and considered for inclusion into the jQuery JavaScript Library or maintained as an official jQuery plugin.
Microsoft will also ship a current release of the jQuery JavaScript Library in both Visual Studio 2010 and ASP.NET MVC as well as continue to host current versions of the library on the Microsoft CDN.
Lastly, Microsoft will be providing resources to assist in QA testing of jQuery in new environments to ensure continued stability and longevity of the library.
We see these contributions as a tremendous benefit to the jQuery effort and community and look forward to continued collaboration with Microsoft.
The jQuery Project is very excited to announce the dates for our first-ever San Francisco Bay Area conference. The conference will be held at the Microsoft Silicon Valley Research Center in Mountain View, California on April 24th and 25th, 2010.
The San Francisco Bay Area conference is the second of four events planned by the jQuery Project in 2010. The first was the jQuery14 event, and additional conferences are being planned in Europe and on the East Coast for later this year.
This venue is the largest that the project has worked with to date (Harvard Law School in ‘07, the MIT Stata Center in ‘08 and Microsoft New England Research Center in ’09) and we expect to sell out very quickly.
Registration is currently scheduled to open on Wednesday, March 17th; tickets will be priced at $199. In addition to General Admission tickets, we’re offering a limited number of discounted student tickets priced at $99, with a valid student ID.
Watch the jQuery blog or jQuery Twitter feed for notification when registration opens.
A brief synopsis of some of the content that you’ll be able to expect:
In addition to two days of jQuery sessions, for the first time we’ll be adding an additional day of jQuery training, prior to the main event. The training will be provided by appendTo and focused on helping you and your team get up to speed on jQuery prior to attending the conference. The training will cover the following topics:
The training will be held on April 23rd at the Microsoft San Francisco offices in downtown San Francisco; tickets will cost $299. All proceeds from training go to the jQuery Project.
Interested in speaking? Please fill out our call for speaking submissions form and watch the jQuery Blog for updates.
jQuery 1.4.2 is now out! This is the second minor release on top of jQuery 1.4, fixing some outstanding bugs from the 1.4 release and landing some nice improvements.
I would like to thank the following people that provided patches for this release: Ben Alman, Justin Meyer, Neeraj Singh, and Noah Sloan.
As usual, we provide two copies of jQuery, one minified (we now use the Google Closure Compiler as the default minifier) and one uncompressed (for debugging or reading).
You can feel free to include the above URLs directly into your site and you will get the full performance benefits of a quickly-loading jQuery.
Additionally you can also load the URLs directly from either Google or Microsoft’s CDNs:
A full list of the API changes can be found in the 1.4.2 category on the jQuery API site.
In this release we’ve added two new methods: .delegate() and .undelegate(). These methods serve as complements to the existing .live() and .die() methods in jQuery. They simplify the process of watching for specific events from a certain root within the document.
For example:
$("table").delegate("td", "hover", function(){ $(this).toggleClass("hover"); });
This is equivalent to the following code written using .live()
:
$("table").each(function(){ $("td", this).live("hover", function(){ $(this).toggleClass("hover"); }); });
Additionally, .live()
is roughly equivalent to the following .delegate()
code.
$(document).delegate("td", "hover", function(){ $(this).toggleClass("hover"); });
There has been some large code rewrites within this release, both for performance and for fixing long-standing issues.
As is the case with virtually every release of jQuery: We’ve worked hard to continue to improve the performance of the code base, making sure that you’re provided with the best performing JavaScript code possible.
According to the numbers presented by the Taskspeed benchmark we’ve improved the performance of jQuery about 2x compared to jQuery 1.4.1 and about 3x compared to jQuery 1.3.2.
Specifically we’ve improved the performance of 4 areas within jQuery:
$("body")
. (Commit)While comprehensive benchmarks like Taskspeed can be interesting if deconstructed into individual sub-tests for further study, as a project we tend to stay away from using them as an accurate measure of true, overall, library performance. Considering how many aspects make up a library, not to mention the different techniques that they offer, cumulative results rarely reflect how an actual user may use a library.
For example, we saw significant overall performance speed-ups in Taskspeed simply by optimizing the $("body")
selector because it’s called hundreds of times within the tests. Additionally we saw large gains by optimizing .bind()
and .unbind()
by a fraction of a millisecond – an inconsequential amount – especially considering that any cases where you would bind hundreds of events you would likely want to use .live()
or .delegate()
instead.
We’ve collected some results from the other major libraries as well but are less interested in those results and far more interested in the performance improvements that we’ve made relative to older versions of jQuery itself.
We will continue to work on optimizing the jQuery code base – indefinitely. It’s always a major concern for us to try and provide the fastest JavaScript/DOM-development experience possible. And yes, there will likely always be ways to gain additional performance – either through internal optimizations or by pushing critical functionality off into browser-land for standardization.
The largest internal changes have come through a much-needed structural rewrite of the events module. Many quirky issues related to event binding have been resolved with these fixes.
Namely event handlers are no longer stored as object properties in jQuery’s internal object store (with metadata attached to the handlers). Instead they’re now stored within an internal array of objects.
If you’ve ever had the opportunity to play around with .data("events")
on a jQuery element you would find that it returns an object with all the event types currently bound, within it.
To enumerate some of the changes that have occurred during this rewrite:
As a side-effect of these changes we had to change the newly-exposed special add/special remove APIs in order to accommodate the new event data objects. Ben Alman is in the process of writing up a large tutorial on jQuery’s special event system and we will be making additional announcements when that occurs.
There were a total of 40 tickets closed in this minor release. Some relating to differences between jQuery 1.3.2 and jQuery 1.4.x, some fixing long-standing issues (like in the case of the event module rewrite).
Raw Data
This is the raw data that we collected to generate the aforementioned charts.
jQuery 1.3.2 jQuery 1.4.1 jQuery 1.4.2 Prototype 1.6.1 MooTools 1.2.4 Dojo 1.4.1 YUI 3.0.0 FF 3.5 2182 806 565 2156 1073 575 1885 FF 3.6 1352 677 519 2067 857 750 1494 Opera 983 697 222 793 678 218 1201 Safari 610 435 252 315 235 238 612 Chrome 1591 703 293 271 312 222 745 IE 8 2470 1937 1141 3045 4749 1420 2922 IE 7 4468 3470 1705 9863 10034 1737 5830 IE 6 6517 4468 2110 13499 11453 2202 7295
In case you’re not following along with the 14 days of jQuery, here’s a summary of what has been released for days 8-14.
On Day 12, the jQuery team released jQuery 1.4.1, the first bug release to jQuery 1.4. jQuery 1.4.1 is now the latest release of jQuery; take a moment to review the 1.4.1 release notes.
On Day 13, the team announced the new jQuery Meetups site. We want to help foster local meetups and eventually try to provide more resources to your groups.
On Day 14, the jQuery UI team released jQuery UI 1.8 Release Candidate 1. The team would love you to test and provide feedback with bugs or comments in the jQuery UI Development forum.
Again, events like these are not possible without support from our great sponsors and from you, the jQuery Community. We’d like to thank everyone who has donated during this campaign. We received donations from 653 people, and we are truly grateful to all who contributed. If you missed the campaign, you can still let us know how much jQuery makes your life easier by sending a tax-deductible donation or by showing our sponsors some love for their support.
Netflix
Netflix, Inc. (NASDAQ: NFLX) is the world’s largest online movie rental service, with more than 11 million subscribers. For only $8.99 a month, Netflix members can instantly watch unlimited movies and TV episodes streamed to their TVs and computers and can receive unlimited DVDs delivered quickly to their homes.
JupiterIT
Jupiter provides expert web application development, support services, and training. Committed to open source, Jupiter collected its global experience delivering enterprise JavaScript applications and made it publically available as JavaScriptMVC.
appendTo
appendTo, the jQuery company, delivers industry-leading jQuery training and support services to the web development community and corporations worldwide. Leveraging the power of the Write Less, Do More JavaScript library and the vast experience of jQuery Team Members, appendTo is at the forefront of propelling the jQuery movement into the next generation of open source technology advancements
Oxide Design
Oxide Design Co. is a communications and information design firm. We specialize in corporate identity, brand strategy, packaging, print, and web site design. We clarify ideas to create effective design.
Fusionary
We are Fusionary, an award-winning web and interactive studio. We’ve been creating things online since 1995 and our clients love us.
The team hopes you enjoyed this online conference celebrating the 1.4 release of jQuery. We would love to hear your feedback. Please submit your feedback in this thread on the new jQuery Forum.
jQuery 1.4.1 is now out! This is the first bug fix release on top of jQuery 1.4, fixing some outstanding bugs from the 1.4 release and touching up some gaps in the API.
I would like to thank the following people that provided patches for this release: Ben Alman, Mike Alsup, Irae Brasil, Matt Curry, Robert Katić, Michael Monteleone, and Karl Swedberg.
As usual, we provide two copies of jQuery, one minified (we now use the Google Closure Compiler as the default minifier) and one uncompressed (for debugging or reading).
You can feel free to include the above URLs directly into your site and you will get the full performance benefits of a quickly-loading jQuery.
A full list of the API changes can be found in the 1.4.1 category on the jQuery API site.
Core
Events
Traversing
Effects
Ajax
Offset
Manipulation
Originally published at 14 Days of jQuery (archived).
Today we’re pleased to announce the brand new jQuery.org web site: The home of the jQuery project.
The jQuery.org site was designed and implemented by jQuery community member Boaz Sender.
You may recognize most of the content from the old jQuery Docs site but it’s been heavily re-organized and presented in a manner more befitting of the larger jQuery project.
This launch goes along with the formalization of the jQuery project, back from when we joined the Software Freedom Conservancy. Having an official home for the larger jQuery project should be good for future growth and organization in the project as a whole. You can learn more about this organization in this video about the jQuery project.
Originally published at 14 Days of jQuery (archived).
Today we’re officially announcing the brand new jQuery Forum. We’ve been using mailing lists, and subsequently Google Groups, over the past 4 years to manage the discussion and community around jQuery. That particular solution has simply not been able to scale to our discussion requirements both in terms of participation and in managing spam.
When looking for a new area to have discussions, we looked at a wide variety of solutions with a few major requirements: It had to be capable of handling both regular discussions and the now-ubiquitous question & answers that occur. Additionally, we wanted something that lowered the barrier to asking a question — something that anyone would be able to use (thus it had to have a good web interface).
We also wanted a solution that would have a low maintenance threshold for the team. This would mean either using a hosted solution in which the team we were working with was very accommodating or using a solution that we host ourselves that was trivially easy to use and had a good community of developers.
We ended up analyzing countless solutions, but in the end we chose to go with Zoho Discussions (Zoho’s announcement about the move). A combination of decisions drove us to this decision:
The jQuery team has transitioned to using the new forum over the past week and have been very pleased with how it’s been working out thus far. Most of the old Google Groups and all of the old jQueryHelp.com posts have been integrated into the new system. We will be doing a final import of the Google Groups posts once we finally close the groups in the next week or two.
We’ve opened up a number of individual forums for discussion.
As time goes by, we’ll certainly open more as needs arise — especially ones for non-English speaking users.
As it stands the two largest outstanding issues that are being actively worked on are:
We’ve collected a number of smaller issues and are communicating actively with the Zoho Discussions team. If you find any more issues please feel free to post them to the About the jQuery Forum forum.
As mentioned before, we analyzed a number of discussion solutions — dozens, in fact. There are a few that we were quite pleased with and were in the final running.
We want to take this opportunity to thank the Zoho Discussions team for all their hard work in helping us transition over to their software. They’ve been incredibly helpful and we’re very excited to to be working with them.
Additionally we want to thank Chrys Bader, Mike Branski, and the rest of the community at the old jQueryHelp.com forum for being supportive and willing to integrate into the new forum setup.
Thanks again to everyone for their help in this transition. We hope to work out most of the kinks very quickly and are looking to smooth sailing from here on out. Feel free to hop onto the forums and be sure to report any problems that you may have.
Originally published at 14 Days of jQuery (archived).
In case you’re not following along with the 14 days of jQuery, here’s a summary of what has been released thus far.
We still have 7 more days of jQuery 1.4 to come with more video’s and more releases to announce.
Again, events like these are not possible without support from our great sponsors and from you, the jQuery Community. We’d like to thank everyone who has donated so far, and we’d like to remind everyone that you will receive a free ebook with the donation of $20 or more throughout the 14 Days of jQuery.
Media Template Giveaway
Each day during the 14 days of jQuery, a web developer will receive a free (gs) Grid-Service account for one year from the jQuery Project’s web hosting provider, Media Temple. A grand prize winner will receive a 13″ MacBook Pro!
In order to enter the contest, you must submit a link to your coolest use of jQuery. A winner will be chosen each day during the 14 Days of jQuery. The grand prize winner will be announced on Friday, January 29th.
Check the Media Template Giveaway webpage for more details about the contest and to see the announced daily winners. There are only 7 days left, so enter now!
Check out jQuery Enlightenment!
jQuery team member Cody Lindley has published the jQuery Enlightenment book, and if you haven’t checked it out yet, you’ll definitely want to. “Each chapter contains concepts essential to becoming a seasoned jQuery developer,”‘” so even if you’ve already got your copy, pick one up for a friend who’s just learning! Even better, a percentage of all sales goes directly back to the jQuery project and helps fund future releases and projects. A big thank you to Cody for his generous donation for the 14 Days of jQuery campaign!
In celebration of jQuery’s 4th birthday, the jQuery team is pleased to release the latest major release of the jQuery JavaScript library! A lot of coding, testing, and documenting has gone into this release, and we’re really quite proud of it.
I want to personally thank Brandon Aaron, Ben Alman, Louis-Rémi Babe, Ariel Flesler, Paul Irish, Robert Katić, Yehuda Katz, Dave Methvin, Justin Meyer, Karl Swedberg, and Aaron Quint who put a lot of work into fixing bugs and getting the release out the door.
As usual, we provide two copies of jQuery, one minified (we now use the Google Closure Compiler as the default minifier) and one uncompressed (for debugging or reading).
NOTE: jQuery 1.4.1 has already been released. Please use that instead of the 1.4 release.
Additionally, Google has provided us with a copy of jQuery hosted on their servers. This copy of jQuery is automatically minified and gzipped – and served from Google’s fast edge cache servers.
You can feel free to include the above URL directly into your site and you will get the full performance benefits of a quickly-loading jQuery.
With jQuery 1.4 we attempted to minimize any large upgrade hassles – maintaining the signatures of all public functions. That being said, please read through the list of potentially-breaking changes to be aware of what might cause problems in your applications.
Below is an overview of all the changes and functionality added to jQuery 1.4. Additionally all of the changes have been documented in the jQuery 1.4 docs.
Many of the most popular and commonly used jQuery methods have seen a significant rewrite in jQuery 1.4. When analyzing the code base we found that we were able to make some significant performance gains by comparing jQuery against itself: Seeing how many internal function calls were being made and to work to reduce the complexity of the code base.
In jQuery 1.4 we’ve significantly reduced the complexity of the most popular methods in jQuery. The full performance details can be found below.
For a while now, you’ve been able to pass a function into .attr()
and the return value of that function is set into the appropriate attribute. This functionalilty has now been extended into all setter methods: .css()
, .attr()
, .val()
, .html()
, .text()
, .append()
, .prepend()
, .before()
, .after()
, .replaceWith()
, .wrap()
, .wrapInner()
, .offset()
, .addClass()
, .removeClass()
, and .toggleClass()
.
Addtionally, for the following options, the current value of the item is passed into the function as the second argument: .css()
, .attr()
, .val()
, .html()
, .text()
, .append()
, .prepend()
, .offset()
, .addClass()
, .removeClass()
, and .toggleClass()
.
This enables code like:
// find all ampersands in A's and wrap with a span
$('a').html(function(i,html){
return html.replace(/&/gi,'<span class="amp">&</span>');
});
// Add some information to the title of the anchors
$('a[target]').attr("title", function(i,title){
return title + " (Opens in External Window)";
});
jQuery 1.4 adds support for nested param serialization in jQuery.param, using the approach popularized by PHP, and supported by Ruby on Rails. For instance, {foo: ["bar", "baz"]}
will be serialized as “foo[]=bar&foo[]=baz”.
In jQuery 1.3, {foo: ["bar", "baz"]}
was serialized as “foo=bar&foo=baz”. However, there was no way to encode a single-element Array using this approach. If you need the old behavior, you can turn it back on by setting the traditional Ajax setting (globally via jQuery.ajaxSettings.traditional
or on a case-by-case basis via the traditional flag).
There are three ways to enable the traditional way of serialization:
// Enables for all serialization
jQuery.ajaxSettings.traditional = true;
// Enables for a single serialization
jQuery.param( stuff, true );
// Enables for a single Ajax requeset
$.ajax({ data: stuff, traditional: true });
More information: jQuery.param() Documentation, jQuery.ajax() Documentation, Commit, Code
If the response to an Ajax request is returned with a JSON mime type (application/json), the dataType defaults to “json” (if no dataType is specified). Additionally, if the response to an Ajax request is returned with a JavaScript mime type (text/javascript or application/x-javascript) , the dataType defaults to “script” (if no dataType is specified), causing the script to automatically execute.
By default, jQuery ignores the Last-Modified header for Ajax requests, preferring to make request and ignore the browser cache. Specifying ifModified: true causes jQuery to use the browser cache if available. jQuery 1.4 will also send the If-None-Match header (for ETag support) if you specify ifModified.
jQuery 1.3 and earlier used JavaScript’s eval
to evaluate incoming JSON. jQuery 1.4 uses the native JSON parser if available. It also validates incoming JSON for validity, so malformed JSON (for instance {foo: "bar"}
) will be rejected by jQuery in jQuery.getJSON and when specifying “json” as the dataType of an Ajax request.
The new HTML5 input types (such as `datetime` and `range`) will be included when you .serialize()
a form.
You can now specify a context for an Ajax request, and all callbacks will have that context set (allowing you to simplify your code and possibly avoid having to use closures, or use other objects).
jQuery.ajax({
url: "test.html",
context: document.body,
success: function(){
jQuery(this).addClass("done");
}
});
The success callback for any ajax request now receives the XMLHttpRequest object as the third argument. Previously this XHR object was only accessible as the return value for $.ajax
and the like.
In jQuery 1.3, the contentType setting was ignored in jQuery.ajax if no data was sent. In jQuery 1.4, the contentType is always sent. This fixes an issue with some backends that used the Content-Type header to decide what kind of response to send.
You can now specify the name of the JSONP callback in jQuery.ajax() using the jsonpCallback option.
Cross-domain ajax (for the browsers that support it) is smoother with jQuery as preflighting is avoided by default.
Ajax requests should now take fewer resources by using onreadystatechange instead of polling.
The performance of .css()
and .attr()
has been improved.
.attr()
takes a function setter (.attr() Documentation)Not only can you use a function with .attr()
, but you can also use the current value of the attribute with the function.
jQuery('<img src="enter.png" alt="enter your name" />')
.attr("alt", function(index, value) {
return "Please, " + value;
});
<input class="food" type="text" />
<input class="food" type="text" />
jQuery("input:text.food").hide();
jQuery("<ul class='sortable'><li>Peanut Butter</li><li>Jelly</li></ul>")
.sortable()
.bind("endsort", function() {
$(":text.food").val(function() {
return $("ul.sortable li:eq(" + $(this).attr("data-index") + ")").text();
});
});</li>
When you create a single element with the jQuery function, you can now pass in an object to add attributes and events at the same time:
jQuery("<div>", {
id: "foo",
css: {
height: "50px",
width: "50px",
color: "blue",
backgroundColor: "#ccc"
},
click: function() {
$(this).css("backgroundColor", "red");
}
}).appendTo("body");
The keys of the object are functions that will be called with each value passed as an argument.
You can now pass in negative numbers for .get() and .eq(). For example, you can select the second-to-last div or, you can access the DOM element for the same:
$("div").eq(-2);
$("div").get(-2);
For convenience, .first()
and .last()
are aliases of .eq(0) and .eq(-1).
.get() has historically returned an Array from the jQuery set. For further clarity, you can use .toArray() to achieve the same thing in jQuery 1.4. Unlike, .get(), however, .toArray() does not take an argument.
In jQuery 1.3, jQuery() returned a jQuery set containing just the document. in jQuery 1.4, it returns an empty jQuery set. This can be useful for creating an empty set and adding elements to it dynamically. Note: The jQuery().ready()
technique still works in 1.4 but it has been deprecated. Please use either jQuery(document).ready()
or jQuery(function(){})
.
A faster path is used when passing in a single tag name.
All three now use the same code path (using document.createElement), improving performance for jQuery("<div></div>")
. Note that if you specify attributes, we use the browser’s native parsing (using innerHTML).
.addClass()
, .removeClass()
, and .hasClass()
methods has seen a 3x performance improvement.You can now call .toggleClass() with multiple selectors and they will all be toggled.
$("div").toggleClass("current active");
It is sometimes desirable to work with the data attached to an element as a complete object. A common example would be wanting to copy the entire data from one element to another. In jQuery 1.4, .data() with no parameter returns the entire object, and .data(Object) sets the object. Keep in mind that this object includes events bound to the element, so use caution.
jQuery uses a unique expando on DOM elements that is used to get the .data() for a particular element. jQuery now avoids creating that expando when data is looked up but no data has been added. This potentially increases performance and avoids polluting the DOM in these cases.
In addition to being able to specify an easing function for an animation you can now specify an easing animation for individual properties. James Padolsey has more information and demos in his blog post.
$("#clickme").click(function() {
$("div").animate({
width: ["+=200px", "swing"],
height: ["+=50px", "linear"],
}, 2000, function() {
$(this).after("<div>Animation complete.</div>");
});
});
If you want to ensure that “this” inside a function will be permanently bound to a particular value, you can use jQuery.proxy to return a new function with that scope.
var obj = {
name: "John",
test: function() {
alert( this.name );
$("#test").unbind("click", obj.test);
}
};
$("#test").click( jQuery.proxy( obj, "test" ) );
You can now pass an object of many events to bind to an element.
$("div.test").bind({
click: function(){
$(this).addClass("active");
},
mouseenter: function(){
$(this).addClass("inside");
},
mouseleave: function(){
$(this).removeClass("inside");
}
});
The change and submit events work reliably across browsers for both normal and live events. We override the normal change and submit events in Internet Explorer and replace them with events that work identically to the other browsers.
focusin
and focusout
are generally equivalent to focus
and blur
but bubble, which helps tremendously if you are writing your own event delegation behavior. Please note that `focus` and `blur` will not work with the live() method; this was a design decision due to the DOM Events spec defining focus/blur do not bubble.
$("form").focusout(function(event) {
var tgt = event.target;
if (tgt.nodeName == "INPUT" && !tgt.value) {
$(tgt).after("<span>nothing here</span>");
}
});
With the exception of ready, focus (use focusin instead), and blur (use focusout instead), all events that can be bound using .bind() can also be live events.
We’re very proud to count some addtional events amongst those supported by live()
. 1.4 introduces cross-browser support forchange
, submit
, focusin
, focusout
, mouseenter
, and mouseleave
via the event delegation in .live()
.
Note that if you need a live focus event, you should use focusin and focusout rather than focus and blur, because, as mentioned, focus and blur do not bubble.
Also, live()
also now accepts a data object, just as bind()
has. (Commit)
You can now specify a context to the selector that will be used to bind a live event. If you do, only elements under that context will be bound. While the elements themselves do not need to exist when you create the live event, the context must exist.
jQuery now checks to see whether the body exists, and falls back to polling for the body if it does not.
A number of DOM manipulation methods have seen dramatic overhauls in performance in jQuery 1.4.
detach()
removes an element from the DOM but does not remove the associated event handlers. This is appropriate for temporarily removing an element to manipulate and then return.
var foo = $("#foo").click(function() {
// do something
});
foo.detach();
// foo retains event handlers
foo.appendTo("body");
The new unwrap method will take the children of a given parent and replace said parent with them. Like so:
<div>annie davey stevie</div>
$('div').unwrap();
annie davey stevie
jQuery caches the resulting nodes created using methods like jQuery("<div>")
and .after("<div>")
. This results in significantly faster performance on pages that do DOM manipulation with strings using these methods.
You can now use before, after, and replaceWith on nodes that are not attached to the DOM. This allows you to do more complex manipulations before inserting the final structure into the DOM. This also prevents reflows from occuring while the manipulation is taking place.
jQuery("<div>").before("Hello").appendTo("body")</div>
In jQuery 1.3, .clone(true) did a deep clone, but did not clone data. In jQuery 1.4, it clones data, which means that events are cloned as well. This uses the same semantics as jQuery.extend, so plain objects and Arrays are cloned, while custom objects are not.
It is now possible to set the offset of an element. Offset, like all setter methods, can now also accept a function as a second argument.
Queueing has undergone an overhaul, improving the experience of working with queues other than the default fx
.
The .delay()
method will delay any further elements in the queue for the specified number of milliseconds. By default, it will use the fx
queue. You can specify an alternate queue as an optional second parameter to the delay function.
$("div").fadeIn().delay(4000).fadeOut();
In jQuery 1.4 the function that’s called is passed in another function, as the first argument, that when called automatically dequeues the next item and keeps the queue moving.
jQuery("div").queue("ajax", function(next) {
var self = this;
jQuery.getJSON("/update", function(json) {
$(self).html(json.text);
next();
};
}).queue("ajax", function() {
$(this).fadeIn();
});
Queues can now be cleared. This will remove any unexecuted functions from the queue, but not stop running functions. Using .clearQueue()
without any parameters will clear the fx
queue.
Any selector string that begins with an ID has an optimization to grab that immediately. ID rooted selectors will always be fastest.
The .index()
method has been rewritten to be more far more intuitive and flexible.
You can now get the index of an element in relation to its siblings:
// get the index of the first <li class="index"> in relation to its siblings:
$("li.current").index()</li>
You can get the index of an element in relation to to the current jQuery collection by passing in a selector or DOM element:
// get the index of the <h3 id="more-info"> in relation to all</h3>
<h3> elements:
$("#more-info").index("h3")</h3>
This is a method form of the :has()
filter. It takes a given jQuery set and returns all of the same elements that contain a given selector.
The new “until” methods function similarly to .nextAll()
, .prevAll()
, .parents()
, but the first argument they take is a selector that will terminate the traversal.
The .add()
now accepts a context. This is primarily useful in a chain when you want to add in addtional elements (returned from an ajax request, for example) and then manipulate those in addition to the others.
The closest method can now accept a context DOMElement as a second argument. Passing in a context will typically make your closest() calls much faster. This also applies to live()
which leverages closest()
internally.
This returns true if there are not any properties on the object. You can only pass in objects to jQuery.isEmptyObject()
, because jQuery performs an iteration on the object that is passed in without any other checks.
jQuery.isPlainObject()
returns true if the object is an object literal and false if the object is another kind of object or a primitive.
jQuery.contains() returns true if both parameters are DOM nodes and the second parameter is contained inside the first.
jQuery.noop is empty function that can be used where a function is required.
In jQuery 1.4, the jQuery.unique()
method, which is used internally in the creation of the jQuery set, always returns results in document order. This means that jQuery sets returned from jQuery functions should be returned in document order.
For example, you can now test for Webkit with jQuery.browser.webkit
.
jQuery no longer attempts to bind events or data to Java applets (which throw exceptions).
For compliance with Caja and because it is slated to be deprecated in the upcoming ECMAScript 5 specification, we have removed all references to arguments.callee
in jQuery core.
One of the major pushes that we made with 1.4 was towards building a more legible, understandable, code base. To achieve that we did some major restructuring of the of the code base internals and began to establish some style guidelines for the code base.
Some of the major changes that were made:
In jQuery 1.4 we’ve fixed 207 bugs (compared to 97 bugs in the 1.3 release).
Additionally we’ve increased our test coverage from 1504 tests in jQuery 1.3.2 to 3060 tests in jQuery 1.4.
The jQuery test suite is 100% passing in all the major browsers (Safari 3.2, Safari 4, Firefox 2, Firefox 3, Firefox 3.5, IE 6, IE 7, IE 8, Opera 10.10, and Chrome).
With jQuery 1.4 we attempted to minimize any large upgrade hassles – maintaining the signatures of all public functions. That being said, please read through the following list to be aware of what might cause problems in your applications.
jQuery.ajaxSettings.traditional = true;
to use traditional parameter serialization. You can also set the behavior on a per-request basis by passing traditional: true to the jQuery.ajax method.We’ve also written a plugin that provides backwards compatibility with every potentially-breaking change that we’ve made in 1.4. Feel free to download and include this plugin, after you’ve included 1.4, if you have any issues upgrading to 1.4.
How to use the plugin:
<script src="http://code.jquery.com/jquery.js"><!--mce:0--></script>
<script src="http://code.jquery.com/jquery.compat-1.3.js"><!--mce:1--></script>
For the performance tests we used the following test suites:
Raw data of the results (all numbers are 1.3.2 vs. 1.4):
# of function calls 547 3 760 3 500 200 896 399 23909 299 307 118 28955 100 28648 201 1662 593 DOM Insertion 558 317 1079 624 1079 516 1155 829 436 332 196 194 243 169 HTML 116 46 281 78 313 78 234 63 134 43 43 42 91 27 CSS/Attributes 703 370 1780 1250 1765 1250 1157 749 629 498 346 184 333 161 CSS 114 52 203 93 118 93 109 47 116 54 58 24 54 22 Classes 553 138 1578 546 1515 501 1033 327 769 298 229 80 173 41 Remove/Empty 3298 286 9030 2344 7921 1703 5282 1266 2898 303 1166 140 1034 122
Originally published at 14 Days of jQuery (archived).