Here is the structure of my navigation bar:
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<span class="d-flex mx-3">
<img src="{{ asset('images/logo-small.png') }}" width="30" height="30" alt="Deliveboo">
<h4 class="mx-3">Deliveboo</h4>
</span>
<hr class="mx-3">
<div class="d-flex justify-content-center p-3">
@if (Auth::guest())
<a class="btn btn-primary text-center" href="{{ route('login') }}"
role="button">Accedi</a>
<a class="btn btn-primary text-center" href="{{ route('register') }}"
role="button">Registrati</a>
@endif
@if (Auth::check())
<a class="btn btn-primary" href="{{ route('restaurants.dashboard') }}" role="button">Vai
alla tua dashboard</a>
@endif
</div>
<hr class="mx-3">
</div>
Below is the code for JavaScript functions:
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "375px";
document.getElementById("root").style.overflow = "hidden";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("root").style.overflow = "auto";
}
</script>
I need to add functionality to close the navbar on clicking outside of it since I am new to JavaScript.
Here is the entire view:
<body id="root">
{{-- HEADER --}}
<header>
...
</header>
{{-- MAIN --}}
<main>
{{-- DELIVEBOO SECTION --}}
<section id="deliveboo-section" class="my-5">
...
</section>
{{-- DEFAULT SECTION --}}
<section id="default-section" class="py-5">
...
</section>
{{-- SECTION SUGGESTED --}}
<section id="suggested" class="m-5">
...
</section>
</main>