Creating two submenus in the sidebar: a step-by-step guide

I am looking to implement a feature where clicking on the sidebar menu will reveal 2 submenus. Here is what I have implemented:

$(document).ready(function () {
    $("[data-toggle]").click(function () {
        var toggle_el = $(this).data("toggle");
        $(toggle_el).toggleClass("open-sidebar");
    });
    $('.parent').click(function () {
        $('.submenu').toggle('visible');
    });
});

body, html {
    height: 100%;
    margin: 0;
    overflow:hidden;
    font-family: helvetica;
    font-weight: 100;
}
.container {
    position: relative;
    height: 100%;
    width: 100%;
    right: 0;
    -webkit-transition:  right 0.4s ease-in-out;
    -moz-transition:  right 0.4s ease-in-out;
    -ms-transition:  right 0.4s ease-in-out;
    -o-transition:  right 0.4s ease-in-out;
    transition:  right 0.4s ease-in-out;  
}

.container.open-sidebar {
    right: 240px;
}

#sidebar {
    position: absolute;
    right: -240px;
    background: #DF314D;  
    width: 240px;
    height: 100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    border-radius: 4px;
}

#sidebar ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

...
... (code continues)
...

Answer №1

$(document).ready(function () {
$("[data-toggle]").click(function () {
    var toggle_el = $(this).data("toggle");
    $(toggle_el).toggleClass("open-sidebar");
});
$('.parent').click(function () {
    $(this).find('.submenu').toggle('visible');
});

});

and

 <li class="parent"> <ul class="submenu"><li>blablabla</li></li>

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

Encountering an error message stating, "Unable to assign value to 'onclick' property"

Currently, I am at a beginner level in Javascript. While working on some exercises, I encountered an issue with the 'onclick' function as mentioned above. Despite going through other queries in this forum, I have not found a solution that works ...

What are the advantages of using REM instead of PX?

When is it ideal to choose rem over px units in CSS? Many articles advocate for using REM to accommodate user preferences, particularly when it comes to font size. However, the focus tends to be solely on font size rather than considering other aspects lik ...

What exactly is the CSS element grouping operator?

I am investigating the concept of element grouping in CSS. Consider the following code snippet: .user-form .group-area .test, .user-form .group-area .test2{} Is it possible to group .test and .test2 elements together like this: .user-form .group-area (. ...

Is there a method to ensure a sequence of jQuery ajax requests are processed in an orderly queue?

I have an array of data (arrData) that I need to loop through (10 elements), making an ajax request for each element. Currently, all the ajax calls are being sent in parallel, causing the server to receive 10 requests at once and respond with the data in n ...

Leveraging jquery's setInterval for automating tasks like a cronjob

I've been experimenting with Cronjobs and I've run into a roadblock. My goal is to have the cronjob execute every X minutes, containing a script with JavaScript that calls an ajax request every second for the next 60 seconds. The ajax call trigge ...

Positioning elements vertically and float them to the left side

I'm struggling to grasp the concept of the float attribute. Here's the code that is causing me confusion: #p1 { border: solid black 3px } <p id="p1" style="float:left">Paragraph 1</p> <a href="https://facebook.com" style="floa ...

javascript retrieving JSON data through an API request from a redirected URL

I am retrieving JSON data from the Glitch API. Upon opening the link, it redirects to a different domain (the domain was changed from gomix.me to glitch.me) When using Postman for both HTTP requests, I receive identical JSON data. However, there is a d ...

Concealing/Revealing Elements with jquery

For hours, I've been attempting to switch between hiding one element and showing another in my script. Here is the code I am using: <script type="text/javascript"> function () { $('#Instructions').hide(); $('#G ...

What is causing the jQuery functions to not be executed in sequence?

Whenever I click the Start button, my function is supposed to run a cycle for 10 iterations. Each iteration generates a number between 1 and 7, which then triggers a series of functions on different objects. The problem is that these functions are not runn ...

Javascript and CSS combo for creating a stylish fade effect

Hey everyone, I have a design challenge where I need to change the color of a picture inside a box when the user hovers over it. I have four boxes like this and my goal is to make everything else fade out when a user hovers over a specific box. Anyone kn ...

Elements within the DIV tag are not displaying in a linear arrangement as intended

I'm having trouble creating a navbar with Bootstrap 4. The items in my div tag are not inline, and I can't align my nav item to the right. Here is the HTML code: <nav class="navbar navbar-inverse "> <div style="display:inline"> ...

Clicking on a row in Rails bootstrap does not produce the desired result

I'm trying to make a row clickable in my Rails app using Bootstrap 4.1.3 to create the table. Rails version: 5.2.1 <tbody> <% @animals.each do |animal| %> <tr data-link="<%= animal_path(animal) %>"> <td&g ...

"Even when hidden, an HTML Div element still occupies space on the

I encountered an issue with my tabbedPage setup. Even though I have hidden content, it still occupies space on the page. Here is the code snippet that I am using: let tabHeader = document.getElementsByClassName("tabbedpage-header")[0]; let tabIndicator = d ...

Is the parent node of the input element the input element itself?

When working with a DOM object obj of type <input>, I encountered an issue where attempting to obtain its parent node using obj.parentNode resulted in the same obj being returned. Is this behavior specific to <input> objects? What other types o ...

Fixing inconsistent font sizes across various browsers

During the development of my website, I couldn't help but notice a significant variance in font sizes between Internet Explorer and other browsers. Here's an example of what my page looks like: I intended for it to resemble the first and second ...

What is the process for including a JavaScript file in an HTML document?

Greetings to all and thank you for taking the time! I have a straightforward query for you.. I have designed an html page featuring only a basemap (open street map). Moreover, I possess a javascript file which utilizes your coordinates to calculate a perce ...

struggling to locate the file index (I've attempted numerous solutions from various forums with no success...)

Apologies for asking a question that may have been asked numerous times before, but I'm encountering some issues and need your help... Thank you in advance! Here is the HTML form I am working with: <form action="action/actionindex.php" method="po ...

"Rearranging the Firefox ghost image by dragging and dropping it

My drag and drop game is working perfectly on all browsers except for Firefox. In Firefox, the ghost image that appears when an item is dragged seems to be positioned very far away from the cursor. Although the ghost image can still be seen on the page, it ...

Take away the Link Navigation feature for dates on the calendar

I need to eliminate the link associated with the date shown in a SharePoint calendar list. Despite using developer's tools, I cannot locate an anchor tag to disable using CSS. My goal is to accomplish this task solely through CSS. Here is the code sn ...

position an element at a higher level than the #top-layer

I developed a custom tool and utilized z-index to position it above all other elements: .customTool { position: fixed; z-index: 99999; } However, this functionality stops working when a modal <dialog /> element is opened in modal mode. As a res ...