Waxolunist Waxolunist - 1 year ago 119
Node.js Question

Load partial html with javascript inside

On my website I load html, which is rendered at the server (nodejs), and insert it at the right position (most time a div with id content).

How would I insert the received html on the client, so that included script tags are executed?

I am using on the client side underscore and handlebars. But vanillajs is also possible of course.

PS: Here is an example to show the difference between

and setting the


esp esp
Answer Source

with jQuery



getElementById('content').innerHTML = loaded_html;

While possible to do it your way, a better idea might be to send json and render pages in the browser using the same templates you (possibly) use in the server. I'm using doT, which I think to be the best of all JavaScript based templates (like EJS, underscore).

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