I’m building a web page form with jquery append() , html() etc and I’m at the point where I have to write the script shown below to the page ( which gets called by some other external include script by ID I think)
What’s the best way to write this script to the page or include it so the external calling script can find it?
Related question:
Do I have to strip all the whitespace out if I use jquery html() or similar method? I always seem to run into trouble with whitespace when outputting large chunks of formatted stuff to page.. thanks
<script id="template-upload" type="text/x-jquery-tmpl">
<tr class="template-upload{{if error}} ui-state-error{{/if}}">
<td class="preview"></td>
<td class="name">${name}</td>
<td class="size">${sizef}</td>
{{if error}}
<td class="error" colspan="2">Error:
{{if error === 'maxFileSize'}}File is too big
{{else error === 'minFileSize'}}File is too small
{{else error === 'acceptFileTypes'}}Filetype not allowed
{{else error === 'maxNumberOfFiles'}}Max number of files exceeded
{{else}}${error}
{{/if}}
</td>
{{else}}
<td class="progress"><div></div></td>
<td class="start"><button>Start</button></td>
{{/if}}
<td class="cancel"><button>Cancel</button></td>
</tr>
</script>
Turns out I was able to write the script in the Question to the page with appendTo() and preserve the ID and type meta data ..
the problem was whitespace and quotes I think.. when I got that part right the appendTo() worked and the other dependent include file worked too