I got the following code on w3school :
<!DOCTYPE html>
<html>
<head>
<script>
function changetext(id)
{
id.innerHTML="Ooops!";
}
</script>
</head>
<body>
<h1 onclick="changetext(this)">Click on this text!</h1>
</body>
</html>
This is working well. Now for the sake of practice, I want want to do it by an external js file. My codes are as follows Html :
<!DOCTYPE html>
<html>
<body>
<p>Click the button to execute the <em>displayDate()</em> function.</p>
<button >Try it</button>
<p id="demo"></p>
<script src="function.js"></script>
</body>
</html>
My js file:
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
onclick='displayDate()';
But above code is not working. What should I do for this.