Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: how to include other .js-files into .js

Is there any jquery plugin (instead of incldeMany) or simple function to include js-files on demand ?

for example:

$.include('myscript.js');  

?

like image 719
Heinrich Avatar asked Apr 08 '10 08:04

Heinrich


People also ask

How do you add .JS file reference in another .JS file?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

Can I call a JS function from another JS file?

As long as both are referenced by the web page, yes. You simply call the functions as if they are in the same JS file.


1 Answers

How about jQuery.getScript()? It's built in to jQuery and works like so:

$.getScript('ajax/test.js', function() {     alert('Load was performed.'); }); 
like image 189
Olly Hodgson Avatar answered Oct 25 '22 03:10

Olly Hodgson