[whatwg] boolean attributes in javascript

How do I correctly set a boolean
attribute<http://dev.w3.org/html5/spec/Overview.html#boolean-attributes>on
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*verbose

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
surprise<http://en.wikipedia.org/wiki/Principle_of_least_astonishment>.
 I find it very hard to believe people will understand:
<script async="" src="..."></script>    or   <script async="async"
src="..."></script>

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

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

Received on Tuesday, 8 December 2009 11:49:45 UTC