External JavaScript File

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.


<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.


function show() {
alert("External JavaScript file.");
<input type="button" value="Show" onclick="show()"/>
<script src="test.js"></script>

Related topics:

Please follow and like us:
Content Protection by DMCA.com