jquery - JavaScript - hide element when click outside not working on mobile phone -


hiding modal windows works fine on desktop computer code

$(document).mouseup(function (e){     if ($("#full_window_dim").is(':visible') && !$("#hodnotenie_hl_okno").is(e.target) && $("#hodnotenie_hl_okno").has(e.target).length === 0){         $("#full_window_dim").fadeout();         $('html, body').removeclass('stop-scrolling'); } }); 

but code not working on mobile phones (i have tried iphone 5 - safari)

how can hide element when users taps outside of window on mobile phones ?

you can use touchstart phones since devices not understand mouse events.

here's code. can include many events want.

function hidemodal(){     if ($("#full_window_dim").is(':visible') && !$("#hodnotenie_hl_okno").is(e.target) && $("#hodnotenie_hl_okno").has(e.target).length === 0){         $("#full_window_dim").fadeout();         $('html, body').removeclass('stop-scrolling');     } }   $(document).on({         "touchstart": function (event) { hidemodal(); },         "mouseup": function (event) { hidemodal(); } }); 

Popular posts from this blog