OK, thanks. The FAQ and doc page made me think I was using an approach that wasn't officially supported. I'll stick with the approach of using true and false -- that results in cleaner code in my experience so far.
Allen On May 12, 4:49 pm, "Karl Rudd" <[EMAIL PROTECTED]> wrote: > As fair as I'm aware, in JavaScript, the boolean values are the > correct values for getting and setting the boolean attributes, like > "disabled" and "readonly". When the HTML is parsed those accessing > those attributes will return either 'true', 'false' or 'undefined'. > > The attr("disabled","disabled") works because a string (or any object) > is considered to be == true (but not === true) > > Karl Rudd > > On Tue, May 13, 2008 at 9:21 AM, AllenH <[EMAIL PROTECTED]> wrote: > > > Is this FAQ correct: > > http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_disable.2F... > > > The example code given for the FAQ is: > > > // Disable #x > > $("#x").attr("disabled","disabled"); > > // Enable #x > > $("#x").removeAttr("disabled"); > > > but I tried this: > > > // Disable #x > > $("#x").attr("disabled",true); > > // Enable #x > > $("#x").attr("disabled",false); > > > and it seems to work fine. I prefer this approach because it is easier > > to chain together several commands, like this: > > > (function($){ > > $.fn.mydisabled = function(trueorfalse) { > > return this.attr('disabled', trueorfalse) > > .css('background-color', trueorfalse ? '#CCC' : '#FFF') > > .css('color', trueorfalse ? '#333' : '#000') > > .css('opacity', trueorfalse ? 0.5 : 1.0); > > } > > })(jQuery); > > > $("#x").mydisabled(true); > > > The documentation page for attr [1] shows the > > attr("disabled","disabled") style but does not mention using true or > > false for the attribute value. > > > [1]http://docs.jquery.com/Attributes/attr > > > So I'm wondering if setting boolean attributes, like disabled and > > readonly, to true or false is correct or is this deprecated behavior > > that might be removed in a future release? > > > Thanks > > > Allen