HTML
and JS
files are linked through a <script>
tag's src
attribute path.
<!DOCTYPE html> <html> <head> <title>Linking JS to HTML file</title> </head> <body> <h1>Header</h1> <button onclick="someFunction()"> Change H1 Text </button> <script src="script.js"></script> </body> </html>
The function defined in JS file is matched to a function defined in HTML file.
// script.js function someFunction() { let heading1 = document.querySelector('h1'); heading1.textContent = 'changed text content'; }