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

Re: Simplifying element creation

From: Sean Hogan <shogun70@westnet.com.au>
Date: Fri, 07 Oct 2011 22:46:35 +1100
Message-ID: <4E8EE69B.5040205@westnet.com.au>
To: Julien Richard-Foy <jrf@zenexity.com>
CC: DOM public list <www-dom@w3.org>
On 7/10/11 7:51 AM, Sean Hogan wrote:
> On 7/10/11 1:20 AM, Julien Richard-Foy wrote:
>>> 3. How is generating a JS structure then calling Element.create(),
>>> node.append(), etc a win compared to generating a string of HTML then
>>> calling innerHTML, insertAdjacentHTML()?
>> It may be better for performance concerns, but itís surely less error
>> prone. When appending strings you have to be careful to close tags at
>> the right place, to escape quotes, etc.
>> Using strings is far less composable than using a proper tree API.
> Either way, you write a function, test it, then you're done.
> Or, more likely, you use a function that someone else has already 
> written and is already in production.

On second thoughts, I'll concede that this can be a minor win for the 
JSON representation of the DOM:
1. If the script containing the JSON compiles this gives you some 
confidence that valid HTML will be generated.
2. If node.append(json), etc run without throwing this increases the 

The same cannot be said when generating a string of HTML and calling 
innerHTML, etc.

Looking at the JSON DOM snippets I've seen and reflecting on the HTML 
snippets I've generated, I would doubt that the HTML approach takes 
significantly more development time (including validating the generated 

NOTE: Where I write JSON above I actually mean a JS structure that can 
represent the DOM, not a JSON string.

Received on Friday, 7 October 2011 11:47:01 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:36:59 UTC