Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jquery toggleClass does not switch css classes when navbar-toggle is clicked

I’m using Bootstrap 3 and I have a div like this:

<div class="col-xs-12 col-sm-1 col-md-1 col-lg-2 login-form" style="margin-top:35px !important">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <button type="button" class="btn btn-info btn-lg btn-block user-actions user-actions-show">Login</button>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <button type="button" class="btn btn-secondary btn-lg btn-block user-actions user-actions-show" style="margin-top:5px;">Register</button>
        </div>
    </div>
</div>

Now I want to switch from user-actions-show class to user-actions-off class which is used for buttons, when the the navbar-toggle is clicked by using jQuery toggleClass:

<script>
        $(".navbar-toggle").click(function(){
            $("user-actions-show").toggleClass("user-actions-off");
        })
</script>

And this is how the class .user-actions-off looks like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.user-actions-off{
     display:none;
}

But now the problem is it does not work out.

So what am I doing wrong here? How can I properly hide those buttons when the navbar-toggle is clicked?


UPDATE:

And this is the navbar-toggle class:

<button class="navbar-toggler navbar-toggle" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

>Solution :

You are missing the . in your script.

Change
$("user-actions-show").toggleClass("user-actions-off");

to $(".user-actions-show").toggleClass("user-actions-off");

That should solve it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading