- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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"); }
Example
The following is the code snippet showing the usage of this method −
<head> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("#driver").click(function(event){ $.getScript('result.js', function(jd) { // Call custom function defined in script CheckJS(); }); }); }); </script> </head> <body> <p>Click on the button to load result.js file −</p> <div id = "stage" style = "background-color:cc0;"> STAGE </div> <input type = "button" id = "driver" value = "Load Data" /> </body>
- Related Articles
- How to include multiple js files using jQuery $.getScript() method?
- How to use external “.js” files in an HTML file?
- How to load external website into an using jQuery?
- How to load external HTML into a using jQuery?
- Why do we have External CSS and JS files
- How to use jQuery.getJSON to load JSON file in jQuery?
- How do I put a jQuery code in an external .js file?
- How to place JavaScript in External Files?
- How to use hasClass() method in jQuery?
- How to use removeClass() method in jQuery?
- How to use jQuery.wrapInner() method in jQuery?
- How to use jQuery.wrapAll() method in jQuery?
- How to use jQuery.text() method in jQuery?
- How to use jQuery.insertBefore() method in jQuery?
- How to use jQuery.insertAfter() method in jQuery?

Advertisements