4 ms·
Which changes (I assume, to .attr()) are affecting you, in particular?
by jeresig 15y ago
Which changes (I assume, to .attr()) are affecting you, in particular?
- troyk 15y agoYes, 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.
- crescentfresh 15y agoRelying 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-attributes/707702#707702 http://stackoverflow.com/questions/706384/boolean-html-attri...
- pak 15y agoThis 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.
- ars 15y agoI 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.
- dmethvin 15y agoThe 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!