Reputation: 735
I am using a javascript templating framework called ICanHazjs.com.
My questions is can I include tags inside of a external javascript file, and if so is there any downsides / compatibility issues with this?
And if I can't what can I attach that will let me add tags.
Upvotes: 3
Views: 836
Reputation: 4535
ICanHaz supports adding templates at runtime with addTemplate
. It's probably your best bet.
Upvotes: 1
Reputation: 4134
if you are only looking for scripts to append you can try this:
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'foo_id';
script.src = 'myjs.js';
document.getElementsByTagName('head')[0].appendChild(script);
otherwise you might try
document.write('<h1>this is pretty ugly in here</h1>');
for document.write there are some common pitfalls :)
Upvotes: 2
Reputation: 270607
If you mean can you include HTML markup inside the Javascript file, no that will not work. The script will be parsed strictly as Javascript.
However, the included Javascript can create HTML markup and add it to the DOM.
Upvotes: 2