views:

1152

answers:

15

A recent new jQuery version has been released, the jQuery v1.4. You can read all about it here. It allows you to do some pretty neat stuff such as:

$("div.test").bind({
  click: function(){
    $(this).addClass("active");
  },
  mouseenter: function(){
    $(this).addClass("inside");
  },
  mouseleave: function(){
    $(this).removeClass("inside");
  }
});

What do you like the most about this new version? What is the thing that made you go "FINALLY!"?


Added a bounty to get more feedback and accept an answer

+58  A: 

Believe it or not, the "FINALLY" moment for me was the addition of delay():

$("#notice").slideDown('500').delay(4000).slideUp('500'); // = Pure awesome :)
Doug Neiner
That's quite awesome indeed
marcgg
Isn't that just a wrapper for `setTimeout`?
DisgruntledGoat
@DisgruntledGoat, The fact that you can use it in method chaining like the example above though is a huge plus.
GSto
This should have been the question accepted. I don't know what went wrong ?
marcgg
Ok this is the problem: http://meta.stackoverflow.com/questions/18944/in-a-bounty-scenario-can-an-answer-from-before-the-bounty-be-automatically-accep ... Sorry about that :\
marcgg
@marcgg No worries. I actually read that Meta question (or a similar one) and understood it to mean you would manually have to pick a winner, not that it would auto accept the highest entry *since* the bounty started... LOL. Oh well :)
Doug Neiner
+19  A: 

I don't really have a favorite, here's an overview of 15 new features for those who don't know what this is all about:

http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/

Natrium
+6  A: 

Well the performance improvements are of course something I appreciate, but I guess I can't say it's a "finally" since it's something that's subject to constant improvement :) The DOM-building (Quick Element Construction) syntax looks really convenient, and the detach method also looks quite usable: it allows you to temporarily remove an object from the DOM, but keeps all the handlers assigned to it, so that it'll work just the same way, when reinserted.

I guess there's not so much a lot of things that I've been missing, but now that these new features are out there, there's a bunch that I'm anxious to start using :)

David Hedlund
+6  A: 

Event delegation for focus and bubble events:

Luke Bennett
+45  A: 

The ability to create elements on the fly in a more terse manner, by passing all attributes as the second argument to jQuery():

jQuery('<div/>', {
    id: 'foo',
    mouseenter: function() {
        // do stuff
    },
    html: jQuery('<a/>', {
        href: 'http://google.com',
        click: function() {
            // do stuff
        }
    })
});

All non-attribute properties map to the corresponding jQuery method. So having html there will call .html() and having click will bind a new click event via .click()...

J-P
I always felt so torn between writing the raw HTML and calling attr() on the element after creation. This is much better :)
Matchu
Why is `$('<div/>', { id: 'foo' })` better than `$('<div id="foo"/>')`? They both work just fine, and the latter is shorter and easier to read and write. (Honest question; I really have no idea!)
Mathias Bynens
Mathias, the point is that values of attributes are often needed to be calculated. Compare: `$('<div id="' + calcId() + '"/>')` and `$('<div/>', { id : calcId() })`
thorn
+13  A: 

For me it was this:

"All Events Can Be Live Events"

"We’re very proud to count some addtional events amongst those supported by live(). 1.4 introduces cross-browser support for change, submit, focusin, focusout, mouseenter, and mouseleave via the event delegation in .live()."

I've been waiting for this on the change event for ages!

James Wiseman
I'm not sure what you mean, could you give an example ?
marcgg
The `live` function binds an event to a "selector", so that if you create new elements that match the selector, they get the event too. Previously it only worked with a handful of events like `click` and `mouseover`. Now it works for practically every event.
DisgruntledGoat
+17  A: 

I am a speed freak so any speed improvement is always welcomed by me

jasondavis
+1'd for the incredibly speed improvements in 1.4!!!
Jarrett Meyer
In particular `find` and `append` were amazing for me.
Alex Bagnolini
+4  A: 

I really like delay() and detach() the most, to be honest. The performance improvements are a huge plus as well but delay() is probably the single most amazing part of it. Simple but ultra useful. No more setTimeouts().

James Thomas
+2  A: 

For me, it's the ability to now write event handlers with the live() handler. I know that live was present in the last version (1.3.2) also, but it wasn't fully supported.

This makes the code infinitely simpler especially if you have most of the DOM being created on the fly or via Ajax requests.

More about live here: http://api.jquery.com/live/

Adhip Gupta
+1  A: 

live() calls with events such as change is a big one for me. I have been wanting this for sometime now.

Prasanna
+2  A: 

It has been very modular since 1.3+. For example, when you don't need the ajax library, it is nice to build without it. Keep file sizes down.

jedierikb
+16  A: 

Best feature in my opinion is allowing functions in setters:

jQuery('li.selected').html(function(i, li) {
   return "<strong>" + li + "</strong>";
});

A lot of code that required $.each can be removed now.

Eric
Could that also be `jQuery('li.selected').wrapInner(<strong />)`
alex
see my comment on the answer bellow
marcgg
+2  A: 

Call me crazy, but just the added number of tests gives me a warm fuzzy feeling. I almost want to upvote every answer :)_

Mark Schultheiss
+2  A: 

I think unwrap() is simple, elegant, and you get an innerHTML present at the end!

The new unwrap method will take the children of a given parent and replace said parent with them. Like so:

<body>
    <div>
        <p>this</p> <p>is</p> <p>fun</p>
    </div>
</body>

$('div').unwrap();

<body>
   <p>this</p> <p>is</p> <p>fun</p>
</body>
Noah Heldman
+2  A: 
$.proxy()

To make sure that this always means this rather than that...

Example from here

MyModule = function() {
  this.$div = $('#testdiv');
  this.myString = "Hi! I'm an object property!";

  this.$div.click($.proxy(this.handleClick, this));
};

MyModule.prototype.handleClick = function() {
  console.log(this.myString); // Hi! I'm an object property!
};

var m = new MyModule();
row1