Make form controls - even
<select>
- read-only.
Won't your <select>
elements accept the readonly
attribute? Readonly.js is a lightweight wrapper to fix that. Not only that, but you can make anything read-only with Readonly.js. Really. :D
Now with Readonly.js 2.0 you can finally drop that old bugger jQuery. Or not, it's your call.
If you're using jQuery, calling readonly
toggles the state of the element.
$('input, select').readonly();
You can also force the state by passing an additional argument; true
for readonly
or false
for editable
.
readonly('input, select', true);
If you're not using jQuery, Readonly.js makes it a breeze:
readonly('input, select');
readonly('input, select', false);
The first argument can be:
- A selector.
- A single element.
- A collection of elements (Array or NodeList).
- A jQuery selection.
This project is licensed under MIT.
- Fork it and make some changes.
- Commit the changes, explaining what you did and why.
- Send a pull request.
- Thank you, you're awesome! ;)