Skip to content
Related Articles

Related Articles

How to use jQuery getScript ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 23 Apr, 2021
View Discussion
Improve Article
Save Article

The jQuery .getScript() method loads a JavaScript file from a server using the GET HTTP method and then executes it.



Let us look at an example to understand how this method works. 

Example: In this example, we will use a URL to load the JavaScript file ‘color.js’ from the server. The file’s functionality is used to add animation to our webpage.


<!DOCTYPE html>
    <script src=
  <body style="text-align: center">
    <h2 id="heading">GeeksforGeeks</h2>
    <p>jQuery | getScript() method</p>
    <button id="button">click here</button>
       /* The getScript method is called 
          by passing url to load color.js 
          and calling a function to add 
          color animations on our page */
        function () {
        // Selecting button and adding event to it.
        $("#button").click(function () {
          .animate({ backgroundColor: "rgb(0, 255, 0)" }, 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!