Display block disappearance persists even after being set to none

Presented below is my menu design:

<div class="span2 main-menu-span">
    <div class="well nav-collapse sidebar-nav">
        <ul class="nav nav-tabs nav-stacked main-menu">
            <li class="nav-header hidden-tablet"><span id="menu1" style="cursor: pointer; cursor: hand;" onClick=checkMenu('menu1')>-</span> Main 1</li>
            <li id='menu1a'><a class="ajax-link" href="menu1a.php"><span class="hidden-tablet">Menu 1 a</span></a></li>
            <li id='menu1b'><a class="ajax-link" href="menu1b.php"><span class="hidden-tablet">Menu 1 b</span></a></li>
        </ul>
    </div>
</div>  

I aim to allow users to hide a section by clicking on the '-' symbol, which should then change to a '+'. However, currently when I press it again, the section does not reappear.

function checkMenu(idVal){
   var idValue = idVal;
   //alert("Mwnu value :" +idValue);
   //alert("Mwnu value :" +document.getElementById(idValue).innerHTML);
   if(document.getElementById(idValue).innerHTML=="+"){
      if(idValue == "menu1" ){
        //alert("Mwnu value :" +idValue);
        document.getElementById("menu1a").style.display="block";
        document.getElementById("menu1b").style.display="block";            
        document.getElementById("menu1").innerHTML ="-" ;
      }         
   }
   if(document.getElementById(idValue).innerHTML=="-"){
      if(idValue=="menu1"){             
        //alert("Mwnu value :" +document.getElementById("menu1a").style.display);
        document.getElementById("menu1a").style.display="none";
        document.getElementById("menu1b").style.display="none";
        document.getElementById("menu1").innerHTML ="+" ;
      }         
   }

Answer №1

To solve this, include an else if statement:

else if(document.getElementById(idValue).innerHTML=="-")
{
...

Answer №2

Upon reviewing the alert message, it is evident that there are spaces within the innerHtml value. It is advised to utilize trim() for trimming the extra spaces. Additionally, consider incorporating an else if statement as suggested by JoshJ.

document.getElementById(idValue).innerHTML.trim()

Check out the demonstration here: http://plnkr.co/edit/YPE59IR4GKxL4JCilNUz?p=preview

UPDATE: In case you are not interested in delving into this issue further, it is recommended to leverage frameworks like bootstrap that offer pre-implemented solutions for such scenarios.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a responsive design for mobile apps in Ionic using CSS

I need help with making my Ionic app responsive across all mobile devices. The design on the page was created using CSS, but it is not displaying properly on every device. How can I ensure that it adapts to different screen sizes? <template> <Io ...

How to read a config file using Node.js in an HTML file

In my configuration file, I have stored all the necessary settings. app: { root: 'rooturl' } I also have an HTML file that serves as a template. My goal is to access the config file from within the HTML file. <img src='rooturl&apos ...

Choosing one item from an array to showcase in a view [Angular]

I've previously inquired about this issue without success. My current challenge involves a store app created with AngularJS. I am trying to implement a feature where clicking on an item will open it in a separate "item" view, displaying only the info ...

Navigate through JSON data to add to an HTML table

HTML <table id="id_kbdata" cellspacing="0" cellpadding="0" > </table> JSON [ { "id":"3", "title":"Doing Business In...", "businessSubjectAreas":[ { "businessSubjectArea":"Market and Sell Products/Service" }, ...

Creating an accessible order for the next and back buttons

Currently, I am working on designing the user interface for a checkout flow. Towards the end of the page, there are 3 buttons available - Next, Back, and Cancel. When viewed on a desktop, the button layout appears as follows: (Back) (Next) Cancel http ...

What is the best way to locate a subnode in XML using XSLT?

I've recently taken over a project that involves using xslt to transform certain html elements. I have been able to successfully match with '/', but I'm encountering issues when trying to run it on a subnode. While searching for soluti ...

Menu with a full-width fluid input field using semantic-ui

I am trying to create a fixed top menu with an image on the left, an input to its right, and another input on the far right. My goal is to have the center input stretch to fill all remaining space between the image and the other input. Although I would no ...

Creating a collapsing drop down menu with CSS

I utilized a code snippet that I found on the following website: Modifications were made to the code as shown below: <div class="col-md-12"> ... </div> However, after rearranging the form tag, the drop-down menu collapse ...

Change the dropdown header behavior from hovering over it to clicking on it

This snippet of code is integrated into our header to showcase the cart. Currently, the dropdown appears when hovering over it. Is there a way to adjust this so that the dropdown shows up when onclick? <a href="#header-cart" class="skip-link skip-cart ...

Ways to customize CSS styles for a single page?

<head> <link href="index.css" rel="stylesheet"> <style> #amor_di_mundo{ color:#ffffff; } </style> </head> <body> <div id='divL'> <div id='amor_di_mundo'>Amor di Mundo</div> <di ...

Aligning table data elements within a division

Currently working on revamping a tech night website for my school. I made some changes to the navbar, switching it from the side to the top. However, I'm struggling to get the table data and menu to center properly within the div. If you'd like ...

Attempting to enlarge logo or image when cursor hovers over it

Seeking to enhance logo/image size when cursor hovers over it, but facing an issue where it enlarges even on areas outside of the image itself - View Example. I followed a tutorial to achieve this effect, and specified the width as 1024x1024 for the logo/i ...

Could Angular be automatically applying margins or padding to my component?

I'm encountering a minor issue.. I'm attempting to create a "Matrix" to construct a snake game in angular, but there seems to be an unremovable margin/padding. Below is my code: <!-- snake.component.html --> <div id="ng-snake-main&q ...

Creating a dropdown menu utilizing JavaScript/jQuery arrays

Looking to create an HTML select menu using a JavaScript array where the keys are used as values for options. The challenge is when entering numbers as keys, they should be accepted in the code. a([selected="No of rooms", 1="1", 2="2", 3="3", 4="4", 5="5" ...

Reorder children in a column layout with the top and bottom child elements reversed

I am attempting to create a layout using flex-direction: column-reverse in order to swap the positions of button 1 and button 2 without modifying the HTML: <button>2</button> <button>1</button> Unfortunately, I'm encountering ...

After trying out the demonstration on the website, I am unable to get my submit button to work

Having trouble with my Formsubmit feature. Despite following the example on the website, my submit button doesn't send anything and the verification isn't reaching my email. Currently working with Angular. <form action="https://formsubmi ...

Can CSS stylesheets be set up to automatically load based on the browser being used to access the website?

I am inquiring because I recently completed a beautiful homepage design and, after viewing the website on Chrome and Safari on OSX, I noticed that certain elements were broken when I opened it in Firefox. In addition, an issue I was experiencing with the ...

The website displays perfectly in Atom, however, it is not functional in any web browser

My website is currently in the development phase, and I'm experiencing issues with certain div elements not positioning correctly once the site goes live. Specifically, the "Follow Us" tab at the bottom of the site, among other divs, has been affecte ...

Space in the middle of a body and a div

After extensively searching for a solution to the issue plaguing my website, I found that there was always an annoying gap at the top of the page. Despite trying various solutions, none seemed to work. Upon inspecting the website in Firefox, I discovered t ...

Can the color of an ion-radio be adjusted when it is not selected?

I am experiencing an issue where I need to change the default color (grey) to a specific color of my choice, such as the primary color. I have attempted the following methods: <ion-col sizeXs="12" sizeMd="6" class="radio-box"> <ion-item line ...