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 15:04:04 -0800
Message-ID: <c9e12660912081504w4373b102if5bf09a534fee9ab@mail.gmail.com>
On Tue, Dec 8, 2009 at 1:41 PM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
> On Tue, Dec 8, 2009 at 1:49 PM, Brian Kuhn <bnkuhn at gmail.com> wrote:
>> How do I correctly set a boolean attribute on a DOM element object in
>> Javascript?
>> var script = document.createElement('script');
>>
>> script.async = true; ? ? ? ?// makes the most sense, but appears go against
>> the spec


HTML content attributes and dom properties are different things.

Like the majority of cases, DOM properties make sense here. The async
property is specified in HTML5, which copied the property from IE.

W3c specs use the term "attribute" to mean "dom property". DOM
properties are not HTML content attributes.

[...]

>
> Setting an attribute foo to '' or 'foo' is the correct way.

getAttribute/setAttribute is not any more correct than DOM properties
but it is less interoperable.

Some content attributes "reflect" object state, others do not. Which
attributes "reflect" varies between browsers and the attribute in
question.

Setting an attribute to the empty string may have the effect of
removing the attribute in some browsers.

Garrett
Received on Tuesday, 8 December 2009 15:04:04 UTC

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