I need to detect if I'm hovering an element using only vanilla javascript. I'm trying this:
this.element.addEventListener('mousemove', function () {
var result = this.element.matches(':hover');
if ( result ) {
this.element.style.backgroundColor = "yellow";
}
console.log(result)
}.bind( this ))
But it isn't working as expected due it always console logs "false".
The use case is: A element have a class, and if I hover it, the class is removed and another class is added.
I know that jQuery has it's "hover" function but I need to accomplish that using only vanilla javascript.