How to use jQuery.getScript() method to load external js files?

The jQuery.getScript( url, [callback] ) method loads and executes a JavaScript file using an HTTP GET request.

Here is the description of all the parameters used by this method −

  • url − A string containing the URL to which the request is sent
  • callback − This optional parameter represents a function to be executed whenever the data is loaded successfully.

Assuming we have following JavaScript content in result.js file −

function CheckJS(){
   alert("This is JavaScript");


The following is the code snippet showing the usage of this method −

      <script src = ""></script>
         $(document).ready(function() {
               $.getScript('result.js', function(jd) {
                  // Call custom function defined in script
      <p>Click on the button to load result.js file −</p>
      <div id = "stage" style = "background-color:cc0;">
      <input type = "button" id = "driver" value = "Load Data" />