News for hackers. Stuff that matters.
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.

There are no comments on this comment yet.