I have the following html:
<div id="box">
<span>stuff.....</span>
</div>
What i’d like to do is create a JavaScript variable with this html… Then with jQuery be able to insert that into the page with something like $('#contentCol').html(mystuff)
Is there an elegant way to do this rather than a long string of html?
ID names are unique, so I changed
id="box"toclass="box", so you can insert the block multiple times.Simply create a function that returns a jQuery object of the type you want. You can pass the HTML inside the span to the function as an argument:
You can use this function in multiple ways:
jsFiddle example