[whatwg] boolean attributes in javascript

Markus Ernst derernst at gmx.ch
Tue Dec 8 15:25:32 PST 2009


Tab Atkins Jr. schrieb:
> On Tue, Dec 8, 2009 at 3:48 PM, Brian Kuhn <bnkuhn at gmail.com> wrote:
>>>   but it's invalid to set it to anything other than the two values I just
>>> mentioned.
>> That's the part I'd like to see changed.  I understand that if it's present,
>> it's on.  So, why can't async="true" be valid?  I think all browser vendors
>> will implement it that way anyway.  They'd be crazy not to.
> 
> Indeed, async="true" does set it to be on.  However, so does
> async="false", async="off", async="no", and any other string you can
> think of that might imply that it's turned off.  Setting it to *any*
> value turns it on, so it's best to avoid values that would lead to
> confusing results.  The two values that are currently valid are the
> minimum necessary, and neither have antonyms that would confuse
> people.

If I understand things right, It looks to me like you talk about 
different things. I think the part of the spec that Brian linked to is 
about HTML, not Javascript (but a link to a section on the DOM handling 
of boolean attributes would be useful, however). I prefer the checked 
attribute as a commen example for boolean attributes:

HTML:
<input type="checkbox" name="box1">
<input type="checkbox" name="box2" checked>
(or: checked="checked", or checked="")

Javascript:
document.forms[0].elements["box1"].checked = false;
document.forms[0].elements["box2"].checked = true;

Or do I misunderstand the discussion?


More information about the whatwg mailing list