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

110
Views
remove class on click other element in filter

I made a filter with jQuery and it works great, I also add a class to the button onclick but I want the class to be removed when clicking on another button (currently it adds the class everywhere).

$(function() {
  $(".filter-name").click(function() {

    selectedClass = $(this).attr("data-rel");
    $(".filter-content div").not("." + selectedClass).hide();
    $(this).toggleClass("active");

    setTimeout(function() {
      $("." + selectedClass).show();
    });

  });
});
.active {
  background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="filters">
  <button class="filter-name" data-rel="all">All</button>
  <button class="filter-name" data-rel="a">A</button>
  <button class="filter-name" data-rel="b">B</button>
</div>

<div id="content">
  <div class="filter-content">
    <div class="all a">a</div>
    <div class="all b">b</div>
    <div class="all a">a</div>
    <div class="all a">a</div>
    <div class="all b">b</div>
    <div class="all a">a</div>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza
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!