

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 include multiple js files using jQuery $.getScript() method?
To use multiple js files, use the same getScript(), which is used to add a single js file. We’re having result.js file with the following code snippet −
function CheckJS(){ alert("This is JavaScript - File1"); }
We’re having result2.js file with the following code snippet −
function CheckJS(){ alert("This is JavaScript – File2"); }
Example
Here's the code snippet to add multiple js files. Here, we will call the function in the above 2 js files −
<head> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function(event){ $.getScript('result.js', function(jd) { // Call custom function defined in script 1 CheckJS(); }); }); $("#button2").click(function(event){ $.getScript('result2.js', function(jd) { // Call custom function defined in script 2 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 = "button1" value = "Load Data" /> <input type = "button" id = "button2" value = "Load 2 Data" /> </body>
- Related Questions & Answers
- How to use jQuery.getScript() method to load external js files?
- How to rename multiple files recursively using Python?
- Rename multiple files using Python
- Rename multiple files using Java
- How to apply multiple CSS properties using jQuery?
- How to copy multiple files in PowerShell using Copy-Item?
- Multiple .java files
- How to merge multiple files into a new file using Python?
- How to spilt a binary file into multiple files using Python?
- How to open multiple files using a File Chooser in JavaFX?
- How to use external “.js” files in an HTML file?
- Using G++ to compile multiple .cpp and .h files
- How to select multiple elements with jQuery?
- How to share common data among multiple Python files?
- How to include CDN Based Version of jQuery in my HTML file?
Advertisements