I have this code below from another post. It sends a message to the console everytime a certain element with an id was hovered over or not. How would I be able to do the same except it sends a message to the console everytime a certain tag was hovered over.
function isHover(e) {
return (e.parentElement.querySelector(':hover') === e);
}
var myDiv = document.getElementById('mydiv');;
document.addEventListener('mousemove', function checkHover() {
var hovered = isHover(myDiv);
if (hovered !== checkHover.hovered) {
console.log(hovered ? 'hovered' : 'not hovered');
checkHover.hovered = hovered;
}
});
--pure javascript to check if something has hover (without setting on mouseover/out)