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

  • Home
  • SEARCH
  • 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 6149001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:22:46+00:00 2026-05-23T19:22:46+00:00

I want to be able to show/hide the rows in a table using jquery.

  • 0

I want to be able to show/hide the rows in a table using jquery. Ideally I want to have buttons above the table to sort the table with.

i.e [Show rows with id:black] [Show rows with id:white] [Show all rows]

I have searched all over but cannot find a solution. Anyone know how i can do this with jquery and make it cross browser compatible?

Thanks (Code below)

<table class="someclass" border="0" cellpadding="0" cellspacing="0" summary="bla bla bla">
<caption>bla bla bla</caption>
<thead>
  <tr id="black">
    <th>Header Text</th>
    <th>Header Text</th>
    <th>Header Text</th>
    <th>Header Text</th>
    <th>Header Text</th>
    <th>Header Text</th>
  </tr>
</thead>
<tbody>
  <tr id="white">
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
</tr>
  <tr id="black">
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
    <td>Some Text</td>
</tr>
</tbody>

  • 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-23T19:22:47+00:00Added an answer on May 23, 2026 at 7:22 pm

    Change your black and white IDs to classes instead (duplicate IDs are invalid), add 2 buttons with the proper IDs, and do this:

    var rows = $('table.someclass tr');
    
    $('#showBlackButton').click(function() {
        var black = rows.filter('.black').show();
        rows.not( black ).hide();
    });
    
    $('#showWhiteButton').click(function() {
        var white = rows.filter('.white').show();
        rows.not( white ).hide();
    });
    
    $('#showAll').click(function() {
        rows.show();
    });
    

    <button id="showBlackButton">show black</button>
    <button id="showWhiteButton">show white</button>
    <button id="showAll">show all</button>
    
    <table class="someclass" border="0" cellpadding="0" cellspacing="0" summary="bla bla bla">
        <caption>bla bla bla</caption>
        <thead>
              <tr class="black">
                ...
              </tr>
        </thead>
        <tbody>
            <tr class="white">
                ...
            </tr>
            <tr class="black">
               ...
            </tr>
        </tbody>
    </table>
    

    It uses the filter()[docs] method to filter the rows with the black or white class (depending on the button).

    Then it uses the not()[docs] method to do the opposite filter, excluding the black or white rows that were previously found.


    EDIT: You could also pass a selector to .not() instead of the previously found set. It may perform better that way:

    rows.not( `.black` ).hide();
    
    // ...
    
    rows.not( `.white` ).hide();
    

    …or better yet, just keep a cached set of both right from the start:

    var rows = $('table.someclass tr');
    var black = rows.filter('.black');
    var white = rows.filter('.white');
    
    $('#showBlackButton').click(function() {
        black.show();
        white.hide();
    });
    
    $('#showWhiteButton').click(function() {
        white.show();
        black.hide();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple hide show jquery script I grabbed from an example site.
I'm using jQuery to show and hide areas on my site with just a
Basically I have a table with many rows. The Table alternates between white and
Hi i just want to be able to toggle to hide/show a div respectively
ok, So I have multiple divs(7) which I want to toggle for show hide.
I want to be able to show the elapsed time in a textview or
I want to be able to show some account information in a ring chart.
Depending on where I use my Class, I want to be able to show
I'm using LaTeX and BibTeX for an article, and I want to able to
I have a scenario where I want to show hierarchical data in a DataGrid

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.