AustinC AustinC - 1 month ago 18
CSS Question

jquery on tap fails to change tooltip location in mobile safari

I have a page with some tooltips that are triggered by mousemove. On mobile, you can tap in the appropriate place to see a tooltip, but then there's no way to get rid of it - it just hangs around. I want them to be able to tap anywhere to discard it. So I tried this:

$(document).on('tap',function(){
$('#tooltip').css("top", -9999);
})


Which does... nothing. I have tried a number of variations on this but it bugs me because I feel like this should work. What am I missing?

Here's a fiddle: https://jsfiddle.net/szevtb55/

The behavior I want is: mobile user taps on area to see tooltip, then taps anywhere to clear the tooltip.

Answer

So this is something to do with jquery - I have no idea what. Anyways, this works:

document.addEventListener('touchstart',function(){
    $('#tooltip').css("top", -9999);
},false)