Is this FAQ correct:
http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_disable.2Fenable_an_element.3F

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

Reply via email to