I am trying to create script tags dynamically under my page using javascript. So far I am able to create it, able to set its type and src. Now my question is, is there any way that instead of defining the src to a different page can I assign its content on the same page? Let me write my code to make it make more sense:
var script = document.createElement("script");
script.type = "text/javascript";
script.src = 'custom.js';
Now is there any way I can assign it the content as well by doing something like this:
script.content = 'document.write("stackoverflow")';
script.html = 'document.write("stackoverflow")';
I am not sure whether they exist or not, but just guessing if i can do something like this.
script.textshould do the trick—of course what you assign must be a valid program.