Example of jQuery.getScript() along with callback

The jQuery.getScript() function takes the URL of a file of JavaScript code as its first argument. It asynchronously loads and then executes that code.

// Dynamically load a script from some other server
jQuery. getScript("http://w3mentor.com/js/myscript.js");

// Load a library and use it once it loads

jQuery.getScript("js/myscript.js", function() {
    $('div').myscript();  // Use the library we loaded
});

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.