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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:40:02+00:00 2026-05-24T09:40:02+00:00

I am trying to create a function toggle menu. Want I want to do:

  • 0

I am trying to create a function toggle menu.

Want I want to do:

  1. When the user clicks on a menuitem div its checkbox should be checked and the minimenu should show underneath.

  2. If a user clicks again on the menuitem div the minmenu should hide and the menuitems checkbox should be uncheched.

My test with one div that is not working:

$('div#category1').click(function(e){
    $('div#minimenu1').removeClass('hidediv');
    $('div#minimenu1').addClass('someclass').show(200);
    $('div#minimenu1').toggle(200);
});
});

My CSS:

.hidediv {display:none;}

My HTML:

        <div class="menuitem" id="category1">
        <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="hidediv" id="minimenu1">
        <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="category2">
        <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 class="hidediv" id="minimenu2">
        <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>

    <input id="submit" name="commit" style="display:none;" type="submit" value="Submit" />
</form>

UPDATE:

Now I have made the code that I want to use, but how do I make an smart function so that I dont need to repeat the code over and over again for each menuitem?

My Jquery code for category1:

$(function () {

        $('div#category1').toggle(function () {

            $('div#minimenu1').removeClass('hidediv');
            $('div#category1').addClass('clicked').show(200);
            $('div#minimenu1').addClass('someclass').show(200);
            $('div#category1 input:checkbox').attr('checked','checked');

        }, function () {
            $("div#category1 input:checkbox").prop("checked", false);
            $('div#minimenu1').addClass('hidediv');
            $('div#category1').removeClass('clicked');

        });
    });

My Jquery code for category2:
$(function () {

        $('div#category2').toggle(function () {

            $('div#minimenu2').removeClass('hidediv');
            $('div#category2').addClass('clicked').show(200);
            $('div#minimenu2').addClass('someclass').show(200);
            $('div#category2 input:checkbox').attr('checked','checked');

        }, function () {
            $("div#category2 input:checkbox").prop("checked", false);
            $('div#minimenu2').addClass('hidediv');
            $('div#category2').removeClass('clicked');

        });
    });
  • 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-24T09:40:03+00:00Added an answer on May 24, 2026 at 9:40 am
    $(function () {
    
            $('div#category1').toggle(function () {
    
                // do the things you want to happen firt time user clicks
    
            }, function () {
                // do the opposite things you want to happen second time user clicks
            });
        });
    

    And for checking checkboxes if you are using the new version of jQuery go for:

    $(".myCheckbox").prop("checked", true);
    

    If not:

    $('.myCheckbox').attr('checked','checked');
    

    You can make your code modular by using the each function and referring to elements using the this keyword (but you need to leave the IDs and add a class to your divs class=’category’ and take it from there using something like this):

    $.each($('div.category'), function () {
    
                var categoryDiv = $(this);
                var relativeMinimenu = categoryDiv.next();
    
                categoryDiv.toggle(function () {
                    relativeMinimenu.removeClass('hidediv').addClass('someclass').show(200);
                    categoryDiv.addClass('clicked').show(200);
                    categoryDiv.find('input:checkbox').attr('checked', 'checked');
                }, function () {
                    categoryDiv.removeClass('clicked').find('input:checkbox').prop("checked", false);
                    relativeMinimenu.addClass('hidediv');
                });
    
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function in C# which will allow me to, when
I'm trying to create a function which takes an array as an argument, adds
Having a problem trying to create a function, as part of a BizTalk helper
I'm trying to create an overridden operator function using both const parameters, but I
Trying to create a user account in a test. But getting a Object reference
I'm trying to create a button to show / hide a div below it,
I've created DIV.cb-toggle, when the user hovers over this div, it animates to Orange,
I've created DIV.cb-toggle, when the user hovers over this div, it animates to Orange,
Im trying to create a function to check for a substring within a string
I am trying to create a function to find the square root of a

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.