Victor Ferreira Victor Ferreira - 2 years ago 97
Javascript Question

Programatically loads Javascript file and load code when it's finished

I'm working in a React project that uses jQuery and I need to import a jQuery library to it.

Basically, what I need right now is a way to load a javascript in my project dynamically and when it finishes loading I need to run a javascript code.

something like this:

//run this code when myscript has finished loading

Answer Source

$.getScript does what you want.

$(function() {
    $.getScript('myscript.js', function() {
        // run when myscript has finished loading
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download