如何在单击子主题菜单时关闭侧边栏菜单

So I have a sidebar menu that close on overlay, but it seems that closing the sidebar when subtopic is clicked seems smoother. I wanted to implement that code without removing the overlay function as well

Right now I have the sidebar menu that close with overlay function

<nav id="sidebar">
            <div id="dismiss">
                <i class="glyphicon glyphicon-arrow-left"></i>
            </div>

            <div class="sidebar-header">
                <h3>Tutorial OnPay</h3>
            </div>

            <ul class="list-unstyled components">
                <p>Topik 1 : Pendaftaran + Pengaktifan + Log Masuk</p>
                <li>
                    <a href="#daftar" data-toggle="collapse" aria-expanded="false">1.1 Pendaftaran OnPay</a>
                    <ul class="collapse list-unstyled" id="daftar">
                        <li><a href="#layari-laman-onpay">1.1.1 Layari Laman Web</a></li>
                        <li><a href="#pilih-subdomain">1.1.2 Pilih Subdomain</a></li>
                        <li><a href="#pilih-email">1.1.3 Pilih Emel</a></li>
                        <li><a href="#pilih-ID-dan-kata-laluan">1.1.4 Pilih ID dan Kata Laluan</a></li>
                        <li><a href="#isi-maklumat-profil-diri">1.1.5 Isi Maklumat Profil Diri</a></li>
                        <li><a href="#pengesahan-spam">1.1.6 Pengesahan Spam/Robot (reCAPTCHA)</a></li>
                        <li><a href="#klik-butang-daftar">1.1.7 Klik Butang Daftar</a></li>
                    </ul>
                </li>
</nav>

Here's the jquery part with the overlay. I wanted to implement when the subtopic is clicked the sidebar automatically close. I tried using the normal codes that i found on google but it seems to not worked.

<script type="text/javascript">
        $(document).ready(function () {
            $("#sidebar").mCustomScrollbar({
                theme: "minimal"
            });

            $('#dismiss, .overlay').on('click', function () {
                $('#sidebar').removeClass('active');
                $('.overlay').fadeOut();
            });

            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').addClass('active');
                $('.overlay').fadeIn();
                $('.collapse.in').toggleClass('in');
                $('a[aria-expanded=true]').attr('aria-expanded', 'false');
            });
        });
    </script>