I'm having an issue with the addeventlistener and "click", I launch my web page but the JS click doesn't seem to execute, I looked around and can't find where the error is, maybe someone can help :-) Also I'd like to dinamically display the number of green cells on the page, maybe someone can give me a clue on this too as a bonus :-) Here's my code:
CSS
.green { background: green; color: white; }
.white { background: white; color: black; }
#sales-list { border: 1px solid black; }
td { padding: 10px; border: 1px solid black; }
HTML
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 3</title>
<link rel="stylesheet" type="text/css" href="Untitled_1.css"/>
</head>
<body>
<script type="text/javascript">
var cells = document.querySelectorAll("td");
for (var i = 0; i < cells.length; i++) {
cells[i].addEventListener("click", function() {
this.className= this.className == "white" ? "green" : "white";
});
}
document.write("Number of green cells: ")
</script>
<table id="sales-list">
<tr>
<td class="white">TEST1</td>
<td class="white">TEST2</td>
<td class="white">TEST3</td>
</tr>
</table>
</body>
</html>