I want to detect if any input element is being hovered over. I have this code below that doesn't work because the .hover() function activates after the if statement occurs (which is weird to me). So is there another way to do this?
function createInput(event) {
thing = 0;
$("input").hover(function() {
thing = 1;
})
if (thing == 0) {
//create a new input bar
}
}
(I don't want to use jquery for this as it does not work)
I want something like this however the code below only works for situations where you want to see if a certain element with an ID is being hovered. It will not work if you want to see if all elements with a certain tag are being hovered:
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)