This is the code of my html file:
<html>
<head>
<script type="text/javascript" src="try1.js"></script>
</head>
<body>
<h1>A Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
And this is the code of my javascript file:
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed";
}
try1.jsfile on the same folder with your HTML file?innerTextinstead ofinnerHTML--it's a lot safer :)