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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:10:28+00:00 2026-05-24T10:10:28+00:00

I am trying to checkbox when the div.menuitem is clicked and then it should

  • 0

I am trying to checkbox when the div.menuitem is clicked and then it should change class and show the content in the div with class of hidediv. When the div.menuitem is again clicked it should remove the class and hide the div again and uncheck the checkbox.

Want I want to do:

  1. Only show the content of the hidediv when the menuitem is pressed. (checkbox should be checked)

  2. When the menuitem is pressed the checkbox should be checked

  3. When the menuitem is clicked again the hidediv should be hidden again. (checkbox unchecked)

  4. And the checkbox should be uncheched

Illustration of my menu form:

<div class="menuitem">
1.Company1
</div>
<div class="hidediv">
1.1 Company 1.1 
1.2 Company 1.2
</div>

<div class="menuitem">
1.Company2
</div>
<div class="hidediv">
1.1 Company 2.1 
1.2 Company 2.2
</div>

My previous Jquery code, which only is trigger when the checkbox is clicked. I want pretty
similar function to this, the checkbox should also be trigghed when the div is clicked:

$('.menuitem input:checkbox').change(function(){
        if($(this).is(':checked')) {
            $('div.hidediv').addClass('someclass').show(200); // not needed it there is another way of identifying the div later to add to hidediv class again.
            $('div.hidediv').removeClass('hidediv');
        } else {
            $('div.someclass').addClass('hidediv').hide(200); 
        }
});
});

My Jquery so far(not working):

$('.menuitem').click(function(e){
$(this).addClass('menuclicked');          
$('div.hidediv').addClass('clicked').show(200);
            $('div.hidediv').removeClass('hidediv');
        } else {
            $('div.someclass').addClass('hidediv').hide(200); 
        }
$('.menuclicked').click(function(e){
$('div.someclass').addClass('hidediv').hide(200); 
});

My HTML:

<form accept-charset="UTF-8" action="/" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>

        <div class="menuitem">
        <label for="search_company1">company1</label>

        <input name="search[company1_is_true]" type="hidden" value="0" /><input id="search_company1_is_true" name="search[company1_is_true]" type="checkbox" value="1" />
        </div>
        <div class="menuitem">
        <label for="search_company3">company3</label>
        <input name="search[company3_is_true]" type="hidden" value="0" /><input id="search_company3_is_true" name="search[company3_is_true]" type="checkbox" value="1" />
        </div>
 <div class="hidediv">
        <div class="menuitem">
        <label for="search_company2">company2</label>
        <input name="search[company2_is_true]" type="hidden" value="0" /><input id="search_company2_is_true" name="search[company2_is_true]" type="checkbox" value="1" />
    <div>
</div>
    <input id="search_submit" name="commit" style="display:none;" type="submit" value="Submit" />
</form>
  • 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-24T10:10:29+00:00Added an answer on May 24, 2026 at 10:10 am

    I can help. I think you are structuring this wrong. You have three fields in your html, with the third being hidden. I assume when you fill in the first one you want nothing to happen, but clicking the second one should show the third field?

    Try this:

    //Use toggle instead of .click()
    $('.menuitem').toggle(function(){
        $('div.hidediv').addClass('clicked').show(200);
    }, function(){
        $('div.hidediv').removeClass('clicked').hide(200);
    });
    

    This will effect all divs with the “menuitem” class, meaning when you click on any of the three it will toggle showing/hiding the div with the “hidediv” class.

    edit you have a couple valid answers here, but I think you’re approaching this wrong. If you go try the jsfiddle posted by another user, whos’ javascript does the same as mine – it reveals the problem I talked about above. You cannot select all three boxes without some clever clicking. Each click will toggle showing/hiding the third check box. Might I suggest modifying your code like so:

    //Use toggle instead of .click()
    $('.toggleMenuItem').toggle(function(){
        $('div.hidediv').addClass('clicked').show(200);
    }, function(){
        $('div.hidediv').removeClass('clicked').hide(200);
    });
    
    <form accept-charset="UTF-8" action="/" method="get">
    
        <div style="margin:0;padding:0;display:inline">
            <input name="utf8" type="hidden" value="&#x2713;" />
        </div>
    
            <div class="menuitem">
                <label for="search_company1">company1</label>
            <input name="search[company1_is_true]" type="hidden" value="0" />
            <input id="search_company1_is_true" name="search[company1_is_true]" type="checkbox" value="1" />
            </div>
    
            <div class="menuitem toggleMenuItem">
                <label for="search_company3">company3</label>
                <input name="search[company3_is_true]" type="hidden" value="0" />
            <input id="search_company3_is_true" name="search[company3_is_true]" type="checkbox" value="1" />
            </div>
    
        <div class="hidediv">
                <div class="menuitem">
                    <label for="search_company2">company2</label>
                    <input name="search[company2_is_true]" type="hidden" value="0" />
                <input id="search_company2_is_true" name="search[company2_is_true]" type="checkbox" value="1" />
                <div>
        </div>
            <input id="search_submit" name="commit" style="display:none;" type="submit" value="Submit" />
    </form>
    

    This will make it so only clicking the checkboxes with the class “.toggleMenuItem” will show the third checkbox.

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

Sidebar

Related Questions

I am trying to show a div if a checkbox is unchecked, and hide
I am trying to remove a class from a div with a checked checkbox
I am trying to make a DIV hide/show depending on whether a Checkbox is
Hey everyone, I am trying to hide/show different html elements (div, etc...) based on
I am trying to hide a div using asp.net checkbox server control. I added
I'm trying to change the background color of a div with a checkbox in
I am trying to use jQuery to show and hide a div when the
I am trying to change the class of a button when a checkbox is
I'm trying to create a checkbox group where the option names can be clicked
I am trying to create a checkbox limit based on a value change example:

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.