[whatwg] boolean attributes in javascript

Brian Kuhn bnkuhn at gmail.com
Tue Dec 8 11:49:45 PST 2009

How do I correctly set a boolean
a DOM element object in Javascript?

var script = document.createElement('script');

   1. script.async = true;        // makes the most sense, but appears go
   against the spec
   2. script.async = 'true';       // worse, but not bad, but also appears
   to go against the spec
   3. script.async = '';            // sets to empty string, but what does
   that really mean?
   4. script.async = 'async';   // sets async = async, which is weird

And then you have the debate on setting the property directly versus using
setAttribute.  Any thoughts on that?

To me, boolean attributes seem to break the rule of least
 I find it very hard to believe people will understand:
<script async="" src="..."></script>    or   <script async="async"

more than:
<script async="true" src="..."></script>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20091208/9c16ac4c/attachment-0002.htm>

More information about the whatwg mailing list