jdee jdee - 2 years ago 182
jQuery Question

JQuery: Build HTML in 'memory' rather than DOM

Is there a way to 'pre-build' a snippet of HTML before adding it to the DOM?

For example:


where $mysnippet doesnt exist in the DOM. I'd like to dynamically build up some lumps of html and then insert them into the page at appropriate points later.

Answer Source

Yes pretty much exactly how you have done it

Some extension of this...

$('<div>').attr('id', 'yourid').addClass('yourclass').append().append()...

and then finally

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download