PASSWORD RESET

Your destination for complete Tech news

How to enable or disable an input with jquery?

273 0
< 1 min read

To enable or disable an input element (such as a text field or button) using jQuery, you can use the prop function. To disable an element, you can set the disabled property to true. To enable an element, you can set the disabled property to false.

Here is an example of how you might use the prop function to disable an input element with the ID “myInput”:

$("#myInput").prop("disabled", true);

And here is an example of how you might use the prop function to enable the same input element:

$("#myInput").prop("disabled", false);

You can also use the attr function in a similar way to set the disabled attribute of an input element. For example:

$("#myInput").attr("disabled", true);
$("#myInput").attr("disabled", false);

Note that the prop function is generally preferred over the attr function when working with form elements, as the prop function is more efficient and better reflects the current state of the element.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.