News for hackers. Stuff that matters.
Re:JQuery 1.6 released by troyk on Tuesday May 03, 2011 @11:37AM (#2510365)
I'd prefer the convenience, as I have yet to code up some jquery and think "damn, .attr is a dog", and now I have to refactor a bunch of code before I can upgrade, and the reality of it is that I won't. jQuery is awesome, but this is the first release that I've not wanted to jump all over
Re:JQuery 1.6 released by jeresig on Tuesday May 03, 2011 @09:48PM (#2512473)
I thought about this discussion a lot more today, discussed the points with the rest of the jQuery core team, and we decided to land an improvement to bring back the boolean attribute handling (with virtually no performance overhead).

The bug and commit are as follows: http://bugs.jquery.com/ticket/9079 https://github.com/jquery/jquery/commit/a9d9f8c5422f171d9c45...

You can start using this code right now with the following version of jQuery: http://code.jquery.com/jquery-git.js

Hope this helps!

Re:JQuery 1.6 released by crescentfresh on Tuesday May 03, 2011 @11:55PM (#2512733)
Trying to get some clarity around this commit. As I understand it this addresses usecases where an element's boolean property is set to true, and .attr() is called as a getter for said property, correct?

Eg

  $(optionElement)
    .prop('selected', true)
    .attr('selected'); // undefined in 1.6, "selected" in 1.6.1
Re:JQuery 1.6 released by jeresig on Wednesday May 04, 2011 @09:18AM (#2513702)
Let's pretend we're working with a checkbox that isn't checked at all:

    <input type="checkbox" id="c"/>

    $("#c").attr("checked") => false     // 1.5.2
    $("#c").attr("checked") => undefined // 1.6
    $("#c").attr("checked") => undefined // 1.6.1
The user then checks the checkbox OR we set the check by doing .prop("checked", true) OR we set the check by doing [0].checked = true, the result would be:

    $("#c").attr("checked") => true      // 1.5.2
    $("#c").attr("checked") => undefined // 1.6
    $("#c").attr("checked") => "checked" // 1.6.1
Note that if we had done .attr("checked", "checked") OR .attr("checked", true) to set the checked property then .attr("checked") would've returned "checked" in both 1.6 and 1.6.1.

In short: In jQuery 1.6.1 .attr(BooleanAttribute) now returns either the name of the attribute (if true) or undefined (if false). Which is consistent with the rest of the API and with the DOM itself.

I should note that all of this is a moot point if you're using .prop("checked") - that will just return true/false consistently based upon the current checked state of the checkbox.

Re:JQuery 1.6 released by jeresig on Tuesday May 03, 2011 @11:41AM (#2510391)
Which changes (I assume, to .attr()) are affecting you, in particular?
Re:JQuery 1.6 released by troyk on Tuesday May 03, 2011 @11:56AM (#2510482)
Yes, I've since read other comments and have a better understanding of the reasoning behind .attr and .prop, so I'm a little less bah-humbug about having to refactor before upgrading. It appears that search/replace .attr('value') => .val(), .attr('checked') => .prop('checked') are the big offenders, but probably need to look closer at .attr('enabled') and .attr('disabled') as well.
Re:JQuery 1.6 released by crescentfresh on Tuesday May 03, 2011 @12:26PM (#2510623)
Relying on the following attributes as returned from .attr() will break, and should get ported to use .prop() instead: 'checked', 'disabled', 'readonly', 'selected' (for <option>s), 'multiple' (for <select>s), 'ismap' (for <img>s), 'defer', 'noresize' (for <frame>s), 'nowrap'.

List compiled (partially) from http://stackoverflow.com/questions/706384/boolean-html-attri...

Re:JQuery 1.6 released by pak on Tuesday May 03, 2011 @12:57PM (#2510747)
This should be linked to or listed directly in the OP.

Really, most people reading the changelog care about "how do I make my existing code work with this"--and the details listed are conceptual, but not all practically relevant.

Re:JQuery 1.6 released by ars on Tuesday May 03, 2011 @05:27PM (#2511733)
I have this code:

  $.fn.setAttr = function(attr, bool) {
    if(bool)
      this.attr(attr, attr);
    else
      this.removeAttr(attr);

    return this;
  }

  $.fn.disabled = function(bool) {
    return this.setAttr('disabled', bool);
  }

  $.fn.checked = function(bool) {
    return this.setAttr('checked', bool);
  }
I assume I should change all attr to prop?

I think you should add two more helpers (like .val):

.checked() and .disabled() - with no parameters they return a boolean, and with a parameter you can pass in true/false to set the property.

Those two are probably the most commonly used properties and if you had them most people could probably ignore attr vs prop.

Re:JQuery 1.6 released by dmethvin on Tuesday May 03, 2011 @08:39PM (#2512325)
The blog entry mentions this, but perhaps without enough detail. Your `.setAttr()` exactly matches the same as the `.attr()` method's new behavior when it's passed a Boolean argument to set. The other two would be great suggestions for 1.7!