There are some attributes in HTML which are "boolean" - browsers treat them as "true" if they are present, regardless of the value. An example of such an attribute is selected on the <option>
tag. Another is checked on <input type="checkbox">
.
If you have a call to setAttribute()
for such an attribute, there seems to be no value you can set to have the browsers consistently behave as though the attribute is missing.
For example
option.setAttribute("selected", false)
will still mark the option selected. null, empty string or undefined don't work either. If anyone knows of a value I can set to achieve my goal, please let me know, but I don't think one exists. (Because of some framework code I use, not calling setAttribute()
, or calling removeAttribute()
is difficult.)
I'm trying to find an exhaustive list of such attributes to special case them. Here's what I have so far:
- selected of
<option>
- checked of
<input>
- disabled, readonly of
<input>
,<select>
,<option>
,<optgroup>
,<button>
,<textarea>
- multiple of
<select>
Please help me complete this list - or point me to an existing one.
See Question&Answers more detail:os