I'm trying to add and remove the class on click event. I'm adding and removing the three classes onclick event of .the-old
, its working properly.
Onclick Event (.the-old)
- add class on button tag (.the-new)
- Add and remove class on ids
#navbar-hamburger-01
and#navbar-closed
JS
$(function() {
$('.the-old').on('click', function() {
//alert('..');
$('#navButtonToggle').addClass('the-new');
$('#navButtonToggle').removeClass('the-old');
$('#navbar-hamburger-01').addClass('hidden');
$('#navbar-closed').removeClass('hidden');
});
$('.the-new').on('click', function() {
alert('..');
$('#navbar-hamburger-01').removeClass('hidden');
$('#navbar-closed').addClass('hidden');
});
});
HTML
<button id="navButtonToggle" type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle repnsive-navbar-toggle the-old">
<div id="navbar-hamburger-01">
<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-closed" class="hidden">
<span class="glyphicon glyphicon-remove"></span>
</div>
</button>
But this function does not working $('.the-new').on('click', function() {})
, even i just try to alert
, but it does not working. However class .the-new
is properly adding onclick event of the-old
. Can any guide me where i'm wrong.