Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:19:36+00:00 2026-05-26T10:19:36+00:00

I have a table with active/inactive users, as well as a drop-down that will,

  • 0

I have a table with active/inactive users, as well as a drop-down that will, once changed, toggle the visibility of active or inactive users. That’s working fine, but I can’t figure out how to keep every other row shaded. I’ve added

$(this).find("#tableUsers tr").not(":hidden").filter(":even").addClass("altr");

to the end of each function once the drop-down is changed, but my guess is all rows regardless of visibility are marked as even or odd at the very beginning and do not change based on if they’re visible or not. Thus, every other row is shaded properly when I load the page (on Active filter), but then the shading gets thrown off once I change the drop-down (blocks of rows are shaded).

Code:

$(document).ready(function(){

    // on load, show only active users
    $('#tableUsers tr').each(function(){
                var status = ($(this).attr('id'));
                if (status == 'userInactive'){
                    $(this).hide();
                }
                else if (status == 'userActive'){
                    $(this).show();
                }               
    });

    $(this).find("#tableUsers tr").not(":hidden").filter(":even").addClass("altr");


    $('#userTypeDropDown').change(function(){
        var option = $(this).val();

        if (option == 'Active'){
            $('#tableUsers tr').each(function(){
                var status = ($(this).attr('id'));
                if (status == 'userInactive'){
                    $(this).hide();
                }
                else if (status == 'userActive'){
                    $(this).show();
                }
            });
            $(this).find("#tableUsers tr").not(":hidden").filter(":even").addClass("altr");
        }

        if (option  == 'Inactive'){
            $('#tableUsers tr').each(function(){
                var status = ($(this).attr('id'));
                if (status == 'userActive'){
                    $(this).hide();
                }
                else if (status == 'userInactive'){
                    $(this).show();
                }
            });
            $(this).find("#tableUsers tr").not(":hidden").filter(":even").addClass("altr");
        }

        if (option  == 'Both'){
            $('#tableUsers tr').each(function(){
                    $(this).show();
            });
            $(this).find("#tableUsers tr").not(":hidden").filter(":even").addClass("altr");
        }

    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:19:36+00:00Added an answer on May 26, 2026 at 10:19 am

    Here’s a working jsfiddle: http://jsfiddle.net/E8wvK/

    I completely rewrote the JavaScript to be much less verbose and more efficient.

    For posterity here’s the code:

    HTML

    <select id="show">
        <option value="">All</option>
        <option value="active">Active</option>
        <option value="inactive">Inactive</option>
    </select>
    <table>
        <tr class="active-user"><td>John Doe</td></tr>
        <tr class="active-user"><td>Jane Doe</td></tr>
        <tr class="inactive-user"><td>Tony Stark</td></tr>
        <tr class="active-user"><td>Bruce Wayne</td></tr>
        <tr class="inactive-user"><td>Clark Kent</td></tr>
        <tr class="inactive-user"><td>Lois Lane</td></tr>
        <tr class="active-user"><td>Peter Parker</td></tr>
        <tr class="active-user"><td>Harry Osborne</td></tr>
        <tr class="active-user"><td>Mary Jane Watson</td></tr>
        <tr class="inactive-user"><td>Bruce Banner</td></tr>
    </table>
    

    CSS

    tr.alt { background:#c0c0c0; }
    

    JS

    function toggleRows() {
        var selected = $('#show').val();
    
        switch (selected) {
            case 'active':
                var $rows = $('.active-user');
                $rows.show();
                $('.inactive-user').hide();
                break;
            case 'inactive':
                var $rows = $('.inactive-user');
                $rows.show();
                $('.active-user').hide();
                break;
            default:
                var $rows = $('tr');
                $rows.show();
        }
        $rows.removeClass('alt').filter(':even').addClass('alt');
    }
    
    toggleRows();
    
    $('#show').change(function(){
        toggleRows();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables, an active table and an inactive table. I want to
I have table with some fields that the value will be 1 0. This
I have a database with a table for active orders and one for inactive
I have a table which has active an inactive entries, active = 1 for
I have table with 50 entries (users with such details like Name Surname Location
I have a field in my database table that use to store an enumeration
I have a table in a SQL Server 2005 Database that is used a
I have a table with check constraint that is ignored by MySQL. I am
I have a table where status can be either GOLD , SILVER , ACTIVE
I have a table that has a field, IsActive, that indicates whether a record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.