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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:42:13+00:00 2026-06-17T02:42:13+00:00

I am making a menu with this HTML. <div class=sidemenu-maincat> <img src=folder/maincat1.jpg alt=Main cat1

  • 0

I am making a menu with this HTML.

<div class="sidemenu-maincat">
    <img src="folder/maincat1.jpg" alt="Main cat1" id="toggle" />
</div>

<div class="sidemenu-subcat">
    <a href="submenu11.html"> - Submenu 11 </a>
</div>
<div class="sidemenu-subcat">
    <a href="submenu12.html"> - Submenu 12 </a>
</div>
<div class="sidemenu-subcat">
    <a href="submenu13.html"> - Submenu 13 </a>
</div>     

<div class="sidemenu-maincat">
    <img src="folder/main-cat2.jpg" alt="Main cat2 /> 
</div>

<div class="sidemenu-subcat">
    <a href="submenu21.html"> > Submenu 21 </a>
</div>
<div class="sidemenu-subcat">
    <a href="submenu22.html"> > Submenu 22 </a>
</div>
<div class="sidemenu-subcat">
    <a href="submenu23.html"> > Submenu 23 </a>
</div> 

I have the “sidemenu-subcat” div hidden and I would like it to show/hide when I press the pictures on in the “sidemenu-maincat” divs. I have tried to do this with Javascript but I can’t figure out how at all. I would like it not to be done with any library.

I’m keeping all my Javascripts in another document and this is the closest I’ve come to solve my problem:

function toggling()
{
    if(document.getElementByClassName("hidden").style.display == "none")
    {
        document.getElementByClassName("hidden") = "block";    
    }
    else
    {
        document.getElementByClassName("hidden") = "none"; 
    }
}

function init()
{
    var toggle = document.getElementsByClassName("toggle");
    toggle.onclick = toggling;
}

I know it’s far from what that needs to be done but it’s the closest I’ve got..

  • 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-06-17T02:42:14+00:00Added an answer on June 17, 2026 at 2:42 am

    Well I do prefer to use a library for this type of thing but I put together a pure javascript example for you. Though there is probably a better way to do it.

    Firstly, each submenu should be contained within the it’s maincat div and given a hidden class so it is hidden on page load.

    Working Example

    .sidemenu-subcat.hidden {
        display: none;  
    }
    
    var sideMenuOptions = document.getElementsByClassName('sidemenu-maincat');
    for (var i = 0; i < sideMenuOptions.length; i++) {
      sideMenuOptions[i].addEventListener('click', function() {
        var subMenuItems = this.getElementsByClassName('sidemenu-subcat');
        for (var s = 0; s < subMenuItems.length; s++) {
          var subItem = subMenuItems[s];
          // if the element is not visible it's offsets will be 0
          if (subItem.offsetWidth === 0 && subItem.offsetHeight === 0) {
            subItem.className = 'sidemenu-subcat';
          } else {
            subItem.className = subItem.className + ' hidden';
          }
        }
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a menu for an app and was pointed to this useful
I am making a css menu. For this I am using a ul .
I'm pretty new to HTML and CSS. I'm making a menu bar horizontal and
I am making a navigational menu in html and css, but i want the
Making this tutorial: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html I have ListActivity-derived class and onCreateContextMenu, onContextItemSelected overrides. I think
i am making a website in php i make left menu like this these
http://www.spencedesign.netau.net/singaporehomemenu.html This is the link to my page. When you click on menu it
I was making a menu today, and I stumbled on this curious case, with
I'm making a menu in jquery. You can see it at http://mywash.dk/testtest/index.html The submenu
I'm making a menu in jquery. You can see it at http://mywash.dk/testtest/index.html The submenu

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.