4 ms·
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 bac
by jeresig 15y ago
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 http://bugs.jquery.com/ticket/9079
https://github.com/jquery/jquery/commit/a9d9f8c5422f171d9c451385fcfd7ed1661ec514 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 http://code.jquery.com/jquery-git.js
Hope this helps!
- crescentfresh 15y agoTrying 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
- jeresig 15y agoLet'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.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]