I'm facing an issue with my responsive menu on mobile phones. It should display two buttons - one for the navigation bar and the other to toggle the side bar by removing the classes hidden-xs and hidden-sm. However, I am having trouble getting the btnToggleSidebar button to respond to the click event. Can someone assist me with this?
Here is the HTML code for the navigation:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed pull-left" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar" style="color:#fff"></span>
<span class="icon-bar" style="color:#fff"></span>
<span class="icon-bar" style="color:#fff" ></span>
</button>
<button type="button" id="btnToggleSidebar" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navbar-ex2-collapse">
<span class="sr-only">Toggle navigation</span>
<i class="glyphicon glyphicon-cog" style="color:#fff"></i>
</button>
<a class="navbar-brand" id="goHome" href="/Home/MyEvents"><span class="logo logo-icon"></span></a>
<a class="navbar-brand" id="goHome" href="/Home/MyEvents">@ViewBag.Configname</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
@*<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>*@
<ul class="nav navbar-nav navbar-right">
<li><a id="username" href="./">@ViewBag.UsernameAndRole <span class="sr-only ">(current)</span></a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
And here is the JavaScript code that should handle the click event:
$(document).on('click', 'button #btnToggleSidebar.navbar-toggle', function () {
alert("defvs");
$("div").toggleClass("hidden-sm").toggleClass("hidden-xs");
});