Disable / Enable Form Element Like Input Using JQuery




Here we consider how to Disable Or Enable An Input With JQuery. Not only for input, we can disable any other HTML element by this way. Here we enable/disable input of type Text using Jquery. Suppose we have a TextBox with ID txtInputID as shown below.

Disable Or Enable Any Form Element Like Input Using JQuery, Disable Form Element Like Input Using JQuery, Enable Form Element Like Input Using JQuery, Disable/Enable Any Form Element Like Input Using JQuery, Jquery Prop, Jquery attr, Jquery, Asp.Net, MVC, PHP, HTML

Enable/Disable can be done by using Jquery prop or attr. Before that we have to consider the version of Jquery.




If Jquery version is 1.6 or above, we can use Jquery prop.

$(function () {
           $("input").prop('disabled', false);
           $("input").prop('disabled', true);
})



$("input").prop('disabled', false); will disable the input here.

$("input").prop('disabled', true); will enable the input back.

Instead of $("input"), you can use ID or Class of the form element.




If Jquery version is 1.5 and below, we can use Jquery attr.

$(function () {
          $("input").attr('disabled', 'disabled');
          $("input").removeAttr('disabled');
})



$("input").attr('disabled', 'disabled'); will disable the input here.

$("input").removeAttr('disabled'); will enable the input back.

By using Jquery prop or attr we can disable any form element.