Dynamically load javascript .js file

/ Published in: JavaScript
Save to your folder(s)

addjs("monkey"); will load "monkey.js" file in the same directory.

Copy this code and paste it in your HTML
  1. var d=document;
  3. function gebt(s){return d.getElementsByTagName(s)}
  5. function addjs(s){
  6. var e=d.createElement("script");
  7. e.src=s+".js";
  8. e.s=s;
  9. e.type="text/javascript";
  10. gebt("head")[0].appendChild(e);
  11. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.