Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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:

.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?

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>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

Create a class whose name is .hide and toggle it to your $(".user-actions-show"); it'll override your existing CSS property to latest CSS property.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!