Issue
I have a HTML form with a few select elements. One of the option in each of these elements has been disabled initially. Example:
<label>Amount: <select name="amount">
<option selected value='0'>Any</option>
<option value="1">100+</option>
<option value="2">200+</option>
<option value="3">500+</option>
<option disabled value="4">Specify</option>
</select></label>
I need to enable them with javascript. Is there a good way to target these elements without using jQuery?
Solution
This will take care of all disabled elements and is simple.
You can do this:
var elems = document.querySelectorAll('[disabled]'); // target all disabled elemnts
for (var i = 0; i < elems.length; i++) {
elems[i].removeAttribute('disabled'); // enable them.
}
Answered By - Amit Joki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.