Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i add javascript file into another javascript file.

e.g. 2 files one.js and two.js

now how can i add two.js into one.js???
Posted

If you're using jQuery, jQuery.getScript() will do it. If not, try creating a new script element with the location of the script set and add it to the document.
 
Share this answer
 
JavaScript
/* jsFirstMain.js */
function inc(filename)
{
var body = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
body.appendChild(script)
}

//example
inc("jsSecondInternal.js");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900