Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript / jQuery - Tap outside an element on an iPhone

I found a great answer on detecting a click outside a div from this question: How do I detect a click outside an element?, which works fantastically.

But I've noticed that it doesn't work on the iPhone when testing my site, if I tap outside the element.

Here is the code (taken directly from that answer)

$('html').click(function() {
    //Hide the menus if visible
});

$('#menucontainer').click(function(event){
    event.stopPropagation();
});
like image 444
shrewdbeans Avatar asked Dec 10 '22 00:12

shrewdbeans


1 Answers

this worked for me :)

$('html').on('touchstart', function(e) {
    $('.navbar-flyout').hide();
})
$(".navbar-flyout").on('touchstart',function(e) {
    e.stopPropagation();
});
like image 149
Yannick Schuchmann Avatar answered Dec 23 '22 02:12

Yannick Schuchmann