Until now I was using the following to disable/enable form fields -
$('#fieldid').attr('disable','disable');
$('#fieldid').removeAttr('disable');
And that got the job done. But yesterday, I absent-mindedly typed the following to enable the field -
$('#fieldid').enable();
And it worked! I silently kicked myself for not trying the the handy 'enable'/'disable' functions built into jQuery (or so I thought), and proceeded to change the line to disable to -
$('#fieldid').disable();
And to my surprise, that did NOT work.
Am I missing something? Why is the enable() function defined but the disable() function is not? And even weirder, I could find no mention of either enable() or disable() in the jquery docs. Does anyone have any explanations?
I'm using jQuery 1.6.
An element can be disabled in HTML by setting disable property to true and enabled again by setting disabled=false. By using jQuery, you can grab the element you want to enable or disable and change this property by using the prop() or attr() function, depending upon the version of jQuery you are using.
We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.
jQuery Script:on('click', clickButton); Then disable the click event when checkbox is ticked. $('document'). ready(function() { $('#chkbox').
jQuery does not support an enable()
method out of the box (and the disable
HTML attribute does not exist either, but that might only be a typo in your question).
Maybe you're using a plug-in that provides that feature? If that's the case, try passing false
to the enable()
method to disable a field:
$('#fieldid').enable(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With