I'm a newbie in javascript and I can't get this to work:
content.js
var testing = document.getElementsByClassName("test")[0];
testing.style.color = "red";
alert('hi');
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<script src="content.js"></script>
<div class="test">hi</div>
</body>
</html>
In fact, it won't even popup the alert message. If I remove the code above "alert('hi');", the alert works fine.
Any ideas?