Re: Simplifying element creation

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 UTC