$input.disabled = true;
or
$input.disabled = "disabled";
Which is the standard way? And, conversely, how do you enable a disabled input?
$input.disabled = true;
or
$input.disabled = "disabled";
Which is the standard way? And, conversely, how do you enable a disabled input?
In jQuery Mobile:
For disable
For enable
Disable true for input type :
If you just want to invert the current state (like a toggle button behaviour):
You can use the jQuery prop() method to disable or enable form element or control dynamically using jQuery. The prop() method require jQuery 1.6 and above.
Example:
jQuery 1.6+
To change the
disabled
property you should use the.prop()
function.jQuery 1.5 and below
The
.prop()
function doesn't exist, but.attr()
does similar:Set the disabled attribute.
To enable again, the proper method is to use
.removeAttr()
In any version of jQuery
You can always rely on the actual DOM object and is probably a little faster than the other two options if you are only dealing with one element:
The advantage to using the
.prop()
or.attr()
methods is that you can set the property for a bunch of selected items.Note: In 1.6 there is a
.removeProp()
method that sounds a lot likeremoveAttr()
, but it SHOULD NOT BE USED on native properties like'disabled'
Excerpt from the documentation:In fact, I doubt there are many legitimate uses for this method, boolean props are done in such a way that you should set them to false instead of "removing" them like their "attribute" counterparts in 1.5
or