Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73875

Why is javascript not being recognised for? [closed]

$
0
0

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,


Viewing all articles
Browse latest Browse all 73875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>