5

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();
});
Community
  • 1
  • 1
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
  • 3
    http://stackoverflow.com/questions/3705937/document-click-not-working-correctly-on-iphone-jquery – pbond May 13 '12 at 18:40

2 Answers2

11

this worked for me :)

$('html').on('touchstart', function(e) {
    $('.navbar-flyout').hide();
})
$(".navbar-flyout").on('touchstart',function(e) {
    e.stopPropagation();
});
Yannick Schuchmann
  • 512
  • 1
  • 5
  • 15
2
var doc = document.documentElement;
doc.addEventListener('click', function (e) { //TODO();});

The trick:

/*Add this line into only mobile css*/
body{cursor:pointer}
Ugur Catak
  • 181
  • 1
  • 9