I have this code. I am using it in Chrome, and the console is not throwing out any errors. See below;
var inputs = document.getElementsByClassName("slot");
for(var i = 0; i < inputs.length; i++) {
inputs[i].addEventListener("click", function(){ alert("WOrks"); });
}
If I change the code to this:
var inputs = document.getElementsByClassName("slot");
for(var i = 0; i < inputs.length; i++) {
inputs[i].addEventListener("onmouseover", function(){ alert("WOrks"); });
}
It does not work at all.
All of the elements in the class "slot" are <td>
elements. What is wrong with this code?
Solution: As per the accepted answer, the first parameter in .addEventListener
should be mouseover
, not onmouseover
.
var inputs = document.getElementsByClassName("slot");
for(var i = 0; i < inputs.length; i++) {
inputs[i].addEventListener("mouseover", function(){ alert("WOrks"); });
}
Use mouseover not onmouseover
Your event handler should respond to mouseover
and not onmouseover
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With