Hide a toggle-able div that is nested within another div with its display set to

Looking to enhance user experience by optimizing menu functionality. Upon the initial click of the menu button, I aim to display only the menu headings. Subsequently, clicking on a specific heading would reveal its associated category content.

How can this be achieved?

Below is my HTML structure:

<div class="container-fluid dropdown_menu" style="display: none;">
                <div class="row">
                    <div class="col-sm-3 menu_column">
                        <div class="row ">
                            <div class="col-xs-12 menu_head">
                                <h2> Health Centers </h2></div>
                        </div>
                         <div class="row">
                            <div class="col-xs-12">
                                <hr class="menu_head_divider">
                            </div>
                        </div>
                        <div class="row" id="menu_content">
                            <div class="col-xs-12">
                            <ul class="list-unstyled">
                                <li><a href="#"><image src="images/List/hospital_icon_menu.png"/> <span class="menu_list_item">Hospitals </span> </a> </li>
                                <li><a href="#"><image src="images/List/hospital_icon_menu.png"/> <span class="menu_list_item">Diagnostics </span> </a> </li>
                                <li><a href="#"><image src="images/List/hospital_icon_menu.png"/> <span class="menu_list_item">Clinics </span> </a> </li>
                                <li><a href="#"><image src="images/List/hospital_icon_menu.png"/> <span class="menu_list_item">Alternative Health Care </span> </a> </li>
                            </ul>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-3 menu_column">
                        [Content for second column]
                    </div>

                    <div class="col-sm-3 menu_column">
                        [Content for third column]
                    </div>

                    <div class="col-sm-3 menu_column" style="border: none;">
                        [Content for fourth column]
                    </div>
                </div>
            </div>

Furthermore, here is the jQuery snippet used:


$(document).ready(function () {
    $("#menu").click(function () {
        $(".dropdown_menu").toggle();
        $(".menu_content").css("display", "none");
    });
});

Answer №1

For assistance, please refer to the following link.

Fiddle

    $(document).ready(function(){
    $('.head').click(function() {
        $(this).siblings('.body:first').toggle('slow')
  });

    $('.head2').click(function() {
        $(this).siblings('.body2:first').toggle('slow')
  });

    $('.head3').click(function() {
        $(this).siblings('.body3:first').toggle('slow')
  });

    $('.head4').click(function() {
        $(this).siblings('.body4:first').toggle('slow')
  });
});

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

Unexpected behavior involving the onchange event, input validation, and the enter key

One challenge I encountered was implementing validation for a date input field in a form. The requirement was to only allow dates starting from today up to a maximum of 3 years in the future. If a valid date is entered, a modal should appear; otherwise, an ...

The function Rotate() does not exist

Within my project, I have set up a canvas where I am able to: Load an image onto the canvas Resize the uploaded image Currently, I am working on implementing a rotate function that allows me to rotate the loaded image within the canvas by holding down th ...

Using both Angular material design and Bootstrap together can provide a seamless

Is it feasible to integrate material design into an Angular app alongside bootstrap without any complications? I am aiming to leverage the grid system of twitter-bootstrap and incorporate the dialogues from material design... ...

Encountering an Uncaught TypeError while trying to read properties of undefined (specifically 'remove') during a Change event is causing an issue for me

Looking to update the icons by changing the class from .fa-plus to .fa-minus for this specific menu section <div class="accordion-menu"> <h2 class="accordion-header" id="subseccOne"> ...

What is the best way to align text in the center of a bootstrap container?

I am in the early stages of learning to code with bootstrap and have encountered a frustrating issue. Every element I add after including the jumbotron component seems to automatically align itself to the left and remain stuck there. I have tried using .te ...

Steps for eliminating the thick border around <thead> and <tfoot> elements in Bootstrap

Is there a way to remove the thick border on the <thead> and <tfoot> elements in Bootstrap 4 that seems a bit unnecessary? I found a forum post addressing this issue for Bootstrap 5, but unfortunately, the fix didn't work for me since I a ...

Wrap a HTML element with another element

Having an issue and uncertain if js can solve it. Let's assume there is a p Element. <p class="test> text text text </p> Can jquery transform the above statement into this. <div class="new_created"> <p class="test> text text ...

Using Knockout to bind an element to the selected value from a dropdown list

When using the following select, I am connecting it to an observable array. <select id="selectProtocols" data-bind="options: optionsAvailable, optionsCaption:'Selecione...', optionsText: 'SimpleDescription', optionsValue:'???&a ...

Guide to customizing Highcharts for extracting targeted JSON information

I've been dedicating a significant amount of time trying to unravel this puzzle. Typically, I prefer researching solutions rather than posing questions, but this challenge has me completely perplexed. My goal is to generate a Highchart using data from ...

What is the best way to use jQuery to only display the form that is checked among the 3 forms shown by checkboxes?

Currently, I am working on creating a feed feature where users can post links, text, or images. Each type of posting has its own form for simplicity. At the moment, I have managed to display each form with a checkbox, but I am struggling to find a way to ...

Enhancing jQuery functionality by including parent elements

Recently delving into the world of jQuery, I've encountered a challenge. I have a script that resizes each image within a specific div. Now, I'm looking to place that resized image inside a non-existent div (creating a parent div). How can I ach ...

Adjusting the standard width of a search bar

Just beginning to explore the world of bootstrap and I'm facing an issue with adjusting the width of a search box. It is currently too close to the picture above and my navigation bar below in the container, making it look unattractive. Using &nbs ...

What steps should I take to design a CSS grid layout similar to this?

I'm currently working on creating a grid layout similar to the designs shown below: https://i.sstatic.net/SHLFe.png While I have been successful in most aspects of the layout, I am facing difficulty with the first column. I'm trying to prevent ...

Facing issues with jQuery and Bootstrap: ERR_CONNECTION_RESET

My jQuery and Bootstrap are causing issues and showing the following error message: GET net::ERR_CONNECTION_RESET GET net::ERR_CONNECTION_RESET Imports: jQuery: <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> ...

Adjust the width of the iframe

I've been tasked with customizing a customer's website, and the admin has given me permission to use my own JavaScript file (myScript.js). How can I manipulate the iframe width from 160px to 200px using DOM Operations? <div id="iframeDiv& ...

Guide on assigning a callback function in JavaScript

In this code snippet, I am initializing a new object variable and passing an object as an argument: const newObj = new customObject({ first : $('#fname').val(), last : $('#lname').val(), fn : function() { alert(this ...

Getting rid of the woocommerce spinner on your web pages: a step-by-step

Is it possible to turn off the preloader/spinner on WooCommerce checkout page by using this CSS code? /* Remove spinner on WooCommerce checkout page */ .woocommerce .blockUI.blockOverlay { position: relative !important; display: none !important; } Desp ...

How to apply unique CSS transitions (with transform) to both a parent and child element individually

My goal is to create a CSS-only "hover" transition where the hover state of one DIV animates another DIV and then animates multiple children inside the second DIV. It seems like I can't animate the child div if the parent is animated. For example, co ...

Determine if an HTML element contains a specific class using JavaScript

Is there a simple method to determine if an HTML element possesses a particular class? For instance: var item = document.getElementById('something'); if (item.classList.contains('car')) Remember, an element can have more than one clas ...

Is there a way to update the content of a div without having to

I'm experiencing difficulties with updating the content of a div without having to reload the page. My setup involves jQuery, PHP, and MySQL. I have attempted the following: $('#divId').load("script.php", function(){ someFunction(); }); ...