Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addEventListener "onmouseover" Not Working on Table Cells

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.

like image 978
aCarella Avatar asked Dec 09 '22 02:12

aCarella


2 Answers

    var inputs = document.getElementsByClassName("slot");
 for(var i = 0; i < inputs.length; i++) {
    inputs[i].addEventListener("mouseover", function(){ alert("WOrks"); });
}

Use mouseover not onmouseover

like image 28
Prince Avatar answered Dec 10 '22 16:12

Prince


Your event handler should respond to mouseover and not onmouseover.

like image 137
hvdd Avatar answered Dec 10 '22 15:12

hvdd