javascript tutorial - [Solved-5 Solutions] Disable/enable an input with jQuery?
- javascript - java script - javascript array
Problem:
Which is the standard way? And, conversely, how do we enable a disabled input?
Solution 1:
Just for the sake of new conventions && making it adaptable going forward (unless things change drastically with ECMA6(????):
and
Solution 2:
Sometimes we need to disable/enable the form element like input or textarea. Jquery helps we to easily make this with setting disabled attribute to "disabled". For e.g.:
To enable disabled element we need to remove "disabled" attribute from this element or empty it's string. For e.g:
Solution 3:
Solution 4:
We can put this somewhere global in our code:
And then we can write stuff like:
Solution 5:
If we just want to invert the current state (like a toggle button behaviour):