I have a bootstrap navbar,whenever and I have a button ,when I click the button the navbar items get displayed/hidden.
I have a toggleClass("foo") in the click of the button and the class also gets added,but when I try to do hasClass("foo") it does not work.
$(".navbar-toggler").click(function () {
$('.selectedMenu').remove();
$(this).toggleClass('active closed');
if ($(this).hasClass(".active")) {
alert("as");
}
});
You don't need the class selector (.) when using hasClass
Change
$(this).hasClass(".active")
to
$(this).hasClass("active")
hasClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With