The src attribute of the script tag is used to add or include external JavaScript files into any number of HTML files. It increases the code reusability.
Syntax:
<script type="text/javascript" src="external.js"></script>
First, create a JavaScript file and then save the file with the .js extension. After that, we can use the src attribute of the script tag to use this already-created file.
test.js
function show() { alert("External JavaScript file."); }
<html> <body> <form> <input type="button" value="Show" onclick="show()"/> </form> <script src="test.js"></script> </body> </html>
Related topics:
- What is JavaScript?
- JavaScript advantages and disadvantages
- Javascript External file
- Javascript isNaN()
- Javascript Undefined and Null
- Javascript Create object
- JavaScript access cookie
- Javascript read cookie
- Javascript get cookie by name
- Javascript detete cookie
- Javascript redirect URL
- Javascript print webpage
- Javascript exceptions