The function that I define inside an onclick
event does not work.
I don't know what I am missing. Also I should mention that I have already checked to see if JavaScript is linked to HTML correctly and it is.
https://jsfiddle.net/5sg4owpu/7/
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Practice 1</title>
<link href="indexStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<p class="hello">Hello There!</p>
<script src="newjavascript.js"></script>
</body>
</html>
CSS:
.hello {
border: 1px solid black;
width: 100px;
background: blue;
}
JavaScript:
var mm = document.getElementsByClassName("hello");
mm.onclick=function () {
alert("It worked!");
};