I have a menu in HTML. When you click "menu", a list opens, click "menu" again, the list closes.
I need the menu to close if the user clicks anywhere on the screen
<script type="text/javascript">
$(function() {
var menuVisible = false;
$('#menuBtn').click(function() {
if (menuVisible) {
$('#menu').css({
'display': 'none'
});
menuVisible = false;
return;
}
$('#menu').css({
'display': 'block'
});
menuVisible = true;
});
$('#menu').click(function() {
$(this).css({
'display': 'none'
});
menuVisible = false;
});
});