1

Possible Duplicate:
How to include multiple js files using jQuery $.getScript() method

I need to import multiple files within a .js file, I'm looking at the getScript jQuery method : http://api.jquery.com/jQuery.getScript/ but this just loads one file wheras I want to load 3.

Is there an alternative method for achieving this ?

1

3 Answers 3

3

You probably want something like this

var files = array('filename1', 'filename2');

for (var file in files) {
    $.getScript(file);
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can call the getScript() method 3 times or as many times as the number of script files you want to import.

Comments

0

you can do this like this, but you will have to call each of the scripts, and the order they load, in this example in file 3 we use the callback for executing a function.

$.get("js/file1.js")
.pipe($.get("js/file2.js"))
.pipe($.get("js/file3.js", {}, function()
{
    runFunction();
});

1 Comment

Deprecation Notice $.pipe method is deprecated since jQuery 1.8. You can read more about it over here. Apart from that, this is a good mechanism.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.