W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

Re: Simplifying element creation

From: Ryosuke Niwa <rniwa@webkit.org>
Date: Mon, 14 Nov 2011 16:12:50 -0800
Message-ID: <CABNRm63EX-uq+E0xKxmGY3WUaWg5CkP+B5ouWYz8t4YxO1or9w@mail.gmail.com>
To: Ojan Vafai <ojan@chromium.org>
Cc: Anne van Kesteren <annevk@opera.com>, "www-dom@w3.org" <www-dom@w3.org>
On Mon, Nov 14, 2011 at 4:04 PM, Ojan Vafai <ojan@chromium.org> wrote:
>
> With a browser-provided html quasi-literal, this could be:
>
> var table = html'<table><tbody></tbody></table>';
>  for (var i = 0; i < labels.length; i++) {
>     table.childNodes[0].append(html'<tr>
>         <td>${labels[i]}</td>
>         <td>
>             <span class="bar" style="width:${some expression}%"></span>
>             <span class="value-container">${values[i]}</span>
>         </td>
>     </tr>');
> }
> element.append(table);
>
> This seems considerably more readable and concise to me and is certainly
> more friendly towards the hoards of jquery developers.
>

Yeah, this code is so much cleaner though I'm not sure generating
unrendered text nodes between tr, td, etc... is desirable or not.

- Ryosuke
Received on Tuesday, 15 November 2011 00:13:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:08 GMT