Alex Rivera | Logout

Dynamically load JS inside JS

Asked 2013-01-25T11:42:12.000
481

I have a dynamic web page where I need to import an external JS file (under an IF condition) inside another javascript file.

I tried to search for a feasible solution but it didn't work.

I have tried loading a JS file to the DOM using document.createElement() but it also didn't work. Apparently the Js was loaded into the DOM but was not accessible in the current JS file.

Solution in jQuery will also be fine

Edit
Report

1 Answer

6

jQuery has $.getScript():

Description: Load a JavaScript file from the server using a GET HTTP request, then execute it.

answered 2013-01-25T11:44:06.257

Your Answer