I invoke a function named Func() in my JS code and it should change a html tag content with innerHTML method but it doesn't work.
HTML code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p id="result">results will be here</p>
</body>
</html>
JavaScript code
function Func(){
var a = "Hello world";
document.getElementById("result").innerHTML = a;
}
Func();
The console shows this error:
Uncaught TypeError: Cannot set property 'innerHTML' of null