Side menu closing when tap-ing on menu item

Hi guys!

I am working on a website and i try to make the side menu (sidr) close when i access a menu item. Usually after i click/tap on one, the menu still stays and i need to close it using the menu button again.

I succeeded to make it work on desktops, but i dont know how to make it on mobile.

Could anyone help me?

Here is the code i used to make it work on desktop:


<script src="js/jquery.sidr.js"></script>
<script>
$(document).ready(function() {
$('#simple-menu').sidr();
});
</script>

<script src="js/jquery.touchswipe.js"></script>

<script>
$(document).click(function () {
$.sidr('close');
});

$(document).keyup(function ( e ) {
var key = e.keyCode || e.which;
if ( key === 27 ) {
$.sidr('close');
}
});

</script>

I’ve received an idea that i should change my code to:

$(document).on(‘click touchstart’, function () {
$.sidr(‘close’);
});

for desktop works fine, but on mobile the menu slides out and than directly slides in again automatically without that i even touch something.

if i use just:

<script>
$(document).on(‘touchstart’, function () {
$.sidr(‘close’);
});

than the menu works good (stays open and when i touch it slides in) but like this it doesnt open a page…

anyone have an idea?