views:

2297

answers:

1

Say I have jquery code like this:

html += '<div class="index">' + item.index + '</div>';

// many more similar html += statements

// load items
$('div').append(html);

This html is getting too unmanageable, so I'd like to move it to an external file. What's the best way to pass variables to the HTML as i load it? Do i just have to load it and then put jquery commands in the first JS file? That's what it seems like, but I'd rather use a more template-like method.

+6  A: 

put HTML where it belongs, in the HTML file. then use a templating plugin on jQuery to expand it.

some template plugins:

Javier
I have been looking for a client side replacement for the ASPx Repeater. Looks like you nailed it. Thanks so much. helpful++
Dr. Zim