jquery - Hide div when clicking outside of it doesn't work on iPad -
i have following code:
$(document).on('click touch', function(e) { var nav = $(e.target).closest('.nav-js-trigger'); var hidden = $(e.target).closest('.show-nav') if ( nav.length > 0 ) { $('.show-nav').not( nav.next().toggleclass('show-nav') ).removeclass('show-nav'); } else if ( hidden.length === 0 ) { $('.show-nav').removeclass('show-nav'); } });
it hides menu div if user clicks outside of it. test this:
- click on menu link.
- click outside of yellow div.
the div should hidden.
the problem this not work on ipad. why?
here fiddle.
i have added click touch
, tried touchend
, touchstart
.
got message:
comments may edited 5 minutes
so i'll post answer instead.
- i suggest using
touchend
in tests,touch
event not exist. maybe tests failed because of browser cache? - have tried putting listener on
document.documentelement
,document.body
and/orwindow
? try vanilla javascript like suggested apple:
document.documentelement.addeventlistener("touchend", function(e){ alert('hello world'); }, false);
Comments
Post a Comment