jQuery pattern for DOM building (from strings)?
colin.clark at utoronto.ca
Thu Sep 11 18:06:41 UTC 2008
On 11-Sep-08, at 1:46 PM, Antranig Basman wrote:
> Dear Noah - this kind of complex conditional DOM building + attachment
> model is just the sort of application that the upcoming Fluid
> Renderer (based on a certain "classical" web framework you may
> have met) will be aimed at. Some initial documentation is at
> which we will be aiming to put into a kind of "usable preview"
> mode for the 0.5 release, with more serious uses in 0.6.
The Renderer will indeed be pretty useful in such cases, once it's
ready. In the meantime, I imagine some practical techniques might be
We have several components that do some self-rendering in cases where
the user-supplied markup is missing stuff. One of the problems with
it's locked off from your users. They can't change the markup or
adjust it if necessary.
Without a templating system, the technique we've used is to provide a
user-configurable "renderer" function. We supply a good default, but
if people want to change the markup that is produced, they can supply
their own renderer function that generates the desired structure.
That way, we take into account Eli's good point about how string
concatenation is faster than doing DOM injection element-by-element,
but without locking up the markup away from the user. It also helps to
break up your self-rendered markup into manageable chunks.
Take a look at the Inline Edit component for an example of how this is
I hope this helps,
Technical Lead, Fluid Project
Adaptive Technology Resource Centre, University of Toronto
More information about the fluid-work