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 855279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:03:08+00:00 2026-05-15T08:03:08+00:00

I want to filter certain rows out of a table and am using classes

  • 0

I want to filter certain rows out of a table and am using classes to categorize the rows.

The below code enables me to show and hide row data categorized as “QUO” and “CAL” (eventually there will be other categories.

Can someone point me towards a more elegant solution, so I don’t have to duplicate code for each category as I have below?

Thanks!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<html>
<head>
    <title>Untitled</title>
    <style>

    </style>
    <script src="Javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    $("#toggle_ac_cal").click(function()                
    {
        var checked_status = this.checked;
        if (checked_status==true)
        {
        $(".ac_cal").show()
        }
        else
        {
        $(".ac_cal").hide()
        }
    });     
    $("#toggle_ac_quo").click(function()                
    {
        var checked_status = this.checked;
        if (checked_status==true)
        {
        $(".ac_quo").show()
        }
        else
        {
        $(".ac_quo").hide()
        }
    });         
    });
    </script>
</head>
<body>
<input type="checkbox" id="toggle_ac_cal" checked="checked" />CAL<br/>
<input type="checkbox" id="toggle_ac_quo" checked="checked" />QUO<br/>
<table>
<tbody>
<tr class="ac_cal">
<td>CAL</td>
<td>10 Oct</td>
<td>John Barnes</td>
</tr>
<tr class="ac_cal">
<td>CAL</td>
<td>10 Oct</td>
<td>Neil Burton</td>
</tr>
<tr class="ac_quo">
<td>QUO</td>
<td>11 Oct</td>
<td>Neil Armstrong</td>
</tr>
</tbody>
</table>
</body>
</html>
  • 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-15T08:03:09+00:00Added an answer on May 15, 2026 at 8:03 am

    You can reduce your code (without changing markup) down to this:

    $("[id^='toggle_'").click(function() {
      $("." + this.id.replace('toggle_','')).toggle(this.checked);
    });
    

    Though, if you gave your toggle elements a class instead, like .toggle you can clean up the original selector, like this:

    $(".toggle").click(function() {
      $("." + this.id.replace('toggle_','')).toggle(this.checked);
    });
    

    You could also give them a class and use the value as the target class, like this:

    <input type="checkbox" class="toggle" value="ac_cal" />
    

    Then your jQuery is just this, short and simple:

    $(".toggle").click(function() {
      $("." + this.value).toggle(this.checked);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NSArray that I want to filter out certain objects using an
When I write out a HTML::Table I want to skip certain rows. This should
I want to filter out certain lines from stack traces using log4j (like net.sf.cglib.*
I need to implement CursorAdapter , where i need to filter out certain rows
I want to filter my DataTable based on certain filtering conditions. Here's my code:
I have an array which I want to filter out certain keys. Let's say
I want to filter rows from a data.frame based on a logical condition. Let's
i want to filter a String by using the \w wildcard, but unfortunately it
In my List, I want to ignore certain entries(create list filter), by ignore I
I have a GridView with an EntityDataSource. I want to filter the rows at

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.