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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:13:58+00:00 2026-05-26T17:13:58+00:00

I have a multiple checkboxes. Checking any of them will make a div visible.

  • 0

I have a multiple checkboxes. Checking any of them will make a div visible. Leaving them unchecked will hide the div. It almost works, thanks to Nick (http://stackoverflow.com/questions/4337378/toggle-div-based-on-checkbox-value) except that I want multiple checkboxes to toggle the div.

HTML:

<div id="somediv">
<input type="checkbox" class="form-checkbox" value="a" name="a">
<input type="checkbox" class="form-checkbox" value="b" name="b">
<input type="checkbox" class="form-checkbox" value="c" name="c">
<input type="checkbox" class="form-checkbox" value="d" name="d">
</div>

<div id="tog">tog content</div>

jQuery:

        var tog = $("#tog").hide();
        $('#somediv .form-checkbox').change(function() {              
          if ($(tog).css('display') == 'none') {
            tog.show();
          }       
        });

Another one:

        var tog = $("#tog").hide();
        $('#somediv .form-checkbox').change(function () {                
            $(tog).toggle(this.checked);
        }).change();

What am I missing?
The issue is when unchecking one of them (not all) hides the div.
The requirement is only if none is checked, then hide. And hidden by default.
If any is checked, so keep it visible, no toggles.

Any hint would be very much appreciated.
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-26T17:13:59+00:00Added an answer on May 26, 2026 at 5:13 pm

    Try –

    var tog = $("#tog").hide();
     $('#somediv .form-checkbox').change(function () {                
       $(tog).toggle($('.form-checkbox:checked').length > 0);
     }).change();
    

    Demo – http://jsfiddle.net/VA4NP/

    This is very similar to your second code sample. It uses $('.form-checkbox:checked').length > 0 as the argument passed to the toggle function, which should return true if any of the checkboxes are checked.

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

Sidebar

Related Questions

I have multiple checkboxes. I want to check and uncheck some of them or
I want have this ability to select multiple items with checkboxes and delete them
i have an html page where i have multiple checkboxes each of them are
I have multiple checkboxes with name=ap[] and want to use jquery to convert the
I have multiple checkboxes in a form. Based on clicking those checkboxes, I show
Brief: Based on a query, I have multiple checkboxes generated dynamically. The value of
I have a celltable in GWT which have checkboxes, to select multiple checkboxes i
I have 5 checkboxes and I have to select multiple checkboxes. I made a
I have multiple dynamic checkboxes. I would like to find out what checkbox was
I have 1 form in with multiple checkboxes in it (each with the code):

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.