W3C home > Mailing lists > Public > whatwg@whatwg.org > December 2009

[whatwg] boolean attributes in javascript

From: Markus Ernst <derernst@gmx.ch>
Date: Wed, 09 Dec 2009 00:25:32 +0100
Message-ID: <4B1EE06C.2000700@gmx.ch>
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?
Received on Tuesday, 8 December 2009 15:25:32 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:54 UTC