I am new to Javascript. I have taken some html5 and javascript code out of a book but it doesen't want to function properly.
(HTML FILE):
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> JavaScript Example </title>
<script src="script.js"> </script>
</head>
<body>
<h1>Static</h1> <h1>Dynamic</h1>
<noscript>JavaScript Is Not Enabled!</noscript>
</body>
</html>
(JAVASCRIPT FILE):
function init()
{
var h1tags = document.getElementsByTagName("h1") ;
h1tags(1).onclick = react ;
}
function react()
{
this.innerHTML = "Clicked!" ; this.style.color = "red" ;
}
onload = init ;
Does anybody understand what is going on here? :)
Thanks,