After creating a responsive bootstrap menu and adding jQuery code to hide the dropdown div when clicking outside of the toggle bar, I encountered an issue. Despite closing the toggle bar by clicking outside of the div, the toggle bar does not display correctly afterwards - it continues to show the cross symbol.
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="navbar-header">
<button type="button" id="ChangeToggle" class="navbar-toggle dropbtn" data-toggle="collapse" data-target="#navbar-collapse-1">
<div id="navbar-hamburger">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</div>
<div id="navbar-close" class="hidden">
<span class="glyphicon glyphicon-remove"></span>
</div>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
</nav>
Jquery:
<script type="text/javascript">
$(function() {
$('#ChangeToggle').click(function() {
$('#navbar-hamburger').toggleClass('hidden');
$('#navbar-close').toggleClass('hidden');
});
});
</script>
<script>
$(document).on('click',function(){
$('.collapse').collapse('hide');
$('#navbar-hamburger').toggleClass('show');
$('#navbar-close').toggleClass('hidden');
})
</script>