Q:

Outside click on Ipad device not working for a Div Close

I am trying to close a div block if they click outside of that div in ipad , but its not working.
Can anyone let me know what I am doing wrong
    if (IOSDevice()) // this is custom function
        {                       
            $(document).bind('touchstart',function(event){     
                // alert(event.target.id);          
                if(event.target.id !="MyDivId"){
                    $('#MyDivId').hide()
event.stopPropagation();
            }
        });

    }

A:

$(document).on('touchstart', function (event) {
    if (!$(event.target).closest('#MyDivId').length) {
        $('#MyDivId').hide()
    }
});

