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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:53:56+00:00 2026-05-16T07:53:56+00:00

I am trying to dynamically filter out content using checkboxes and jquery. Being new

  • 0

I am trying to dynamically filter out content using checkboxes and jquery.

Being new to jquery, I’m not sure on how to do this properly, so if any can help that would be great.

I have got this code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" >
        $(document).ready(function(){
            $("#test").change(function()
            {    
                if ($(this).is(":checked"))
                {
                        $("#example").hide();

                }else{
                        $("#example").show();
                }

            });
        });
    </script>
</head>
<body>
    <input type="checkbox" id="test"/>
    <input type="checkbox" id="test2"/>

    <div id="example">Example</div>
    <div id="example2">Example2</div>
</body>
</html>

I am trying to make it so that both checkboxes work dynamically, meaning that I don’t have to hard code the id in like above, which only works for the first checkbox. I want to have multiple checkboxes so was wondering how to do this. Do I get the id on check and insert somehow?

Any help would be great, thanks.

  • 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-16T07:53:57+00:00Added an answer on May 16, 2026 at 7:53 am

    I could give your checkboxes a class like this:

    <input type="checkbox" id="test" class="cb" />
    <input type="checkbox" id="test2" class="cb"/>
    
    <div id="example">Example</div>
    <div id="example2">Example2</div>​​​​​​​​​​​​​​​​
    

    The use that when binding and get the ID on the fly, like this:

    $(document).ready(function(){
      $(".cb").change(function() {    
        $("#" + this.id.replace('test', 'example')).toggle(this.checked);
      }).change();  //match the initial show/hide match
    });​
    

    You can give it a try here, instead of show/hide this uses .toggle(bool), and we’re selecting the matching <div> element by transforming the ID, replacing test with example and fetching that element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to dynamically load a Javascript file using jQuery I keep getting a
I'm trying to dynamically create alert messages using the jQuery plugin for Bootstrap CSS.
I am trying to dynamically filter search results. Every result has tags associated with
I am trying to dynamically filter table cell contents according to a search box.
I'm trying to dynamically add some hyperlinks to a RichTextBox using WPF and C#
This bug is driving me absolutely crazy. I'm trying to filter a number of
I am trying to build a query dynamically. It's initial state is fine. This
I'm trying to select the inner value of the first sibling - using jQuery
I'm trying to dynamically filter (or collect) a list based on type: If I
I am trying to dynamically create filters for a rallycardboard by using a QueryFilter

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.