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

[whatwg] boolean attributes in javascript

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Tue, 8 Dec 2009 17:40:04 -0800
Message-ID: <c9e12660912081740s59adaf54obebf6e6f961e3e12@mail.gmail.com>
On Tue, Dec 8, 2009 at 4:49 PM, Dean Edwards <dean.edwards at gmail.com> wrote:
> On 08/12/2009 23:04, Garrett Smith wrote:
>>
>> Setting an attribute to the empty string may have the effect of
>> removing the attribute in some browsers.
>
> Which browsers/properties?
>

s/removing the attribute/setting a false value.

Try setting a 'checked' property of an input checkbox in IE.

<input type="checkbox" checked id="checkboxInput">

checkboxInput.setAttribute("checked", "");

will un-check a checkbox in IE.

The phenomenon is explained by two factors:
1) In IE < 8, attributes are properties (IE8 has some fixes)
2) Setting a boolean property to a non-boolean value may result in
boolean conversion.
Received on Tuesday, 8 December 2009 17:40:04 UTC

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