I'm encountering unwanted behavior when using JQuery's $.on("click", function(){});
on touch devices. This is my code below:
Code:
$(".team").on("mouseover", teamMouseOver);
$(".team").on("mouseout", teamMouseOut);
$(".team").on("click", teamThumbClicked);
function teamMouseOver(event){
console.log(event.type);
}
function teamMouseOut(event){
// Do something
}
function teamThumbClicked(event){
console.log("Clicked!");
}
Problem:
With the code above, tapping on a .team
element on a touch device simultaneously triggers both listeners, giving me the following console log:
mouseover
Clicked!
Question
Why is mouseover
being triggered on a touch device? This is not the behavior that I would expect from a device that doesn't have a mouse. Is this a bug? What event should I be using so "mouseover" only gets fired when it's an actual mouse pointer that's entering?
My JQuery version is 2.2.4.
mouseover
and I hide it onclick
. If these two events are triggered simultaneously, the tooltip stays visible, when it should be hidden because you clicked. That's why I don't needmouseover
to be triggered when the device doesn't have a mouse. I thought that's whattouch
events were for. Did JQuery do this on purpose to simulate :hover effects? – Mimas"mouseover"
event listener if"touchstart"
happens before"clicked"
. It's convoluted, but it was the only way I found to allow for devices that had both mouse and touch inputs. – Mimas