Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery seems to have an enable function, but not a disable function. Why?

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.

like image 916
Anupam Jain Avatar asked May 10 '11 18:05

Anupam Jain


People also ask

How to disable function in jQuery?

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.

How to disable field in jQuery?

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.

How to disable and enable onclick event in jQuery?

jQuery Script:on('click', clickButton); Then disable the click event when checkbox is ticked. $('document'). ready(function() { $('#chkbox').


1 Answers

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);
like image 161
Frédéric Hamidi Avatar answered Sep 27 '22 23:09

Frédéric Hamidi