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 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 Divs show and hide (with an animation) using the following script (I
ok, So I have multiple divs(7) which I want to toggle for show hide.
I have 3 checkboxes and 2 divs. I want to be able to show
I have a scenario where I want to show hierarchical data in a DataGrid
I want to show and hide a label and its control. I can do
I have a varchar field full of text and I want to be able
I implemented this Jquery show/hide code and everything works fine except that the box
I only have very basic knowledge on Javascript and I want to be able
I need to be able to hide/show multiple div tags on the same page
I have a collapsible div implemented in js, the function of which is show/hide

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.