I am trying to create a collapsible navbar menu:
<div class="collapse navbar-collapse" id="navbarCollapsible">
.. menu items ..
</div>
My goal is to hide the menu whenever a user clicks outside of it (not just when clicking the menu button again):
$(document).ready(function() {
const navbarCollapsible = document.getElementById('navbarCollapsible');
$('.container').on("click", function() {
navbarCollapsible.hide();
});
});
However, I encountered this error:
Uncaught TypeError: navbarCollapsible.hide is not a function
Edit:
I was able to solve it using the following method:
$(navbarCollapsible).collapse("hide");
Now, I am wondering how I can achieve the same result without using jQuery?
Although I am currently using jQuery, I know that it's not necessary for Bootstrap 5 - so how can I utilize the hide
method as mentioned in the documentation without jQuery?