- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 external “.js” files in an HTML file?
Create external JavaScript file with the extension .js. After creating, add it to the HTML file in the script tag. The src attribute is used to include that external JavaScript file.
If you have more than one external JavaScript file, then add it in the same web page to increase performance of the page.
Let’s say the following new.js is our external JavaScript file −
function display() { alert("Hello World!"); }
Now add the external JavaScript file to the HTML web page −
<html> <body> <form> <input type="button" value="Result" onclick="display()"/> </form> <script src="new.js"> </script> </body> </html>
- Related Articles
- How to use jQuery.getScript() method to load external js files?
- How do I put a jQuery code in an external .js file?
- Including an external stylesheet file in your HTML document
- How to write JavaScript in an External File?
- How to read an external JSON file in JavaScript
- When should I use an Inline script and when to use external JavaScript file?
- How to place JavaScript in External Files?
- How to include another HTML file in an HTML file?
- How to include an external JavaScript inside an HTML page?
- How to include multiple js files using jQuery $.getScript() method?
- How do we upload external file on a website using HTML forms?
- How to read an image file in external storage with runtime permission in android?
- How to write an image file in external storage with runtime permission in android?
- How to add a container for an external (non-HTML) application in HTML5
- How to use the tag to define a relationship to an external resource?

Advertisements