Well, as mentioned earlier, jQuery 1.4 is now open to the public, ready for download, use, and commenting… :-)
And with this new release also comes a brand new API site, “[e]very single method has been rewritten from the bottom-up to provide the best possible information about how jQuery works”! In conjunction with Packt Publishing, the new API site borrows heavily from the jQuery Reference Guide, providing deeper documentation, including better explanations and more examples. Honestly, while the old documentation was occasionally frustrating because it was so thin, typically all I want are code examples (as programmers, I think usually we get what we need by just reading a few lines of code, right?).
For those that feel they already thoroughly know their version of jQuery, there is a new page on the API site to tell you only what’s new and improved in version 1.4; very helpful! You can actually feature track all the way back to 1.0, in case you ever need that…
And probably more important is the list of possible upgrade killers, be sure to check this list twice to be sure what’s naughty and nice before upgrading your site! And also note that right below that short list of killers is a plug-in you can add after 1.4 to make it compatible with 1.3… These kids are crazy!!
Some of the bigger-ticket items I see are:
- Whereas you could previously pass a function into
.attr()
, you can now also pass a function into.css()
,.attr()
,.val()
,.html()
,.text()
,.append()
,.prepend()
,.before()
,.after()
,.replaceWith()
,.wrap()
,.wrapInner()
,.offset()
,.addClass()
,.removeClass()
, and.toggleClass()
. - Additionally, you will now receive an attribute’s current value as a second parameter when using
.css()
,.attr()
,.val()
,.html()
,.text()
,.append()
,.prepend()
,.offset()
,.addClass()
,.removeClass()
, and.toggleClass()
, so you can do something like this:
$('a[target]').attr("title", function(i,title){ return title + " (Opens in External Window)"; });
Notice how the anonymous function receivestitle
along with the iterativei
? - Where jQuery previously ignored
lastModified
information and always fetched a file regardless of browser cache, ETag support has been added so you can now specifyifModified: true
to utilize browser cache and save bandwidth when possible. - jQuery will now auto-detect a JSON mime-type, such as
application/json
or a script mime-type, such astext/javascript
orapplication/x-javascript
. - The use of
eval
to parse JSON has been replaced by the native JSON parser, if available, andjQuery.getJSON
will now ignore malformed JSON when the JSON mime-type is specified. - You can now specify a JSONP callback name when making
.ajax()
requests by using thejsonpCallback
option. .ajax()
now utilizesonreadystatechange
rather than polling, so your Ajax calls should be lighter and faster!- A number of speed improvements have been implemented, most notably:
.css()
by 2x
.html()
nearly 3x
.addClasss()
,.removeClass()
and.hasClass()
by 3x.remove()
and.empty()
by more than 4x!
- And a number of new methods have been added, most notably:
.first()
and.last()
methods, which are just are aliases of.eq(0)
and.eq(-1)
, but certainly easier to remember and write. You may have noticed above that.eq(-1)
is how you get.last()
, well now you can also can use.eg(-2)
for “next to last”, etc..detach()
, which removes from the DOM, but does not affect its event handlers, meaning you can easily detach an element from the DOM, manipulate it, and then.append()
it..unwrap()
, which allows you to remove a parent node, such as:
<body><div><p>Text</p></div></body>
$('div').unwrap();
<body><p>Text</p></body>
.delay()
, which allows you to, well, delay something, a la:
$('div').fadeIn().delay(4000).fadeOut();
Nice!!.has()
, similar to:has()
, sort of filters a set of elements.nextUntil()
,.prevUntil()
, and.parentsUntil()
, which work similarly to.nextAll()
,.prevAll()
, and.parents()
, but with a traversal terminating argument
There’s even a video of four of the jQuery dudes talking about the release, if you really want to geek-out…
Is that about enough? I know it is for me… As usual, I will be keeping an eye on The 14 Days of jQuery for the next, oh, 13 days or so, and will let you all know of anything I find interesting!
Happy upgrading,
Atg