From the original SO question Disable/enable an input with jQuery?
I want to enable and disable elements of an HTML page (be they inputs, divs, buttons, etc.).
How can I solve it using jQuery?
From the original SO question Disable/enable an input with jQuery?
I want to enable and disable elements of an HTML page (be they inputs, divs, buttons, etc.).
How can I solve it using jQuery?
jQuery 1.6+
To change the property
disabled
you must use the function.prop()
function.jQuery 1.5 and below
The function
.prop()
doesn't exist, but it.attr()
works similarly: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 current DOM object, and it's probably a bit faster than the other two options if it's just one element:
.prop ()
The advantage of using the or methods.attr ()
is that you can set the property for a bunch of selected items.Note: In 1.6 there is a method
.removeProp()
that sounds a lot likeremoveAttr()
, but SHOULD NOT BE USED on native properties as'disabled'
Excerpt from the documentation:Translation :
In fact, I doubt there are many legitimate uses for this method, boolean properties are made in such a way that you should set them to false instead of "removing" them like their "attribute" equivalents in 1.5