

- 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 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 Questions & Answers
- How to use jQuery.getScript() method to load external js files?
- How do I put a jQuery code in an external .js file?
- Header files “stdio.h” and “stdlib.h” in C
- Including an external stylesheet file in your HTML document
- How to write JavaScript in an External File?
- HTML5 <input type=“file” accept=“image/*” capture=“camera”> display as image rather than “choose file” button
- How to read an external JSON file in JavaScript
- How to place JavaScript in External Files?
- When should I use an Inline script and when to use external JavaScript file?
- Use of parameter “basepath_datavolumes_es” in global configuration file in SAP HANA
- How to “return an object” in C++?
- How to include an external JavaScript inside an HTML page?
- How to use “OR” condition in MySQL CASE expression?
- How to use “not in” query with C# LINQ?
- How to use “window.print()” function to print a page?
Advertisements