Displaying a div on click is simple with CSS and JQuery, but what if you want it to stay visible even after a second click? By utilizing classes within <li> tags instead of buttons

My current code involves clicking on a menu, which should reveal a list where each item has a corresponding section that slides down and slides back up when clicked. However, only the sliding down functionality is working at the moment. I'm new to jQuery, so please go easy on me! I would prefer not to make significant changes to my code as I might get stuck again if I do. If possible, thank you in advance!

jQuery(document).ready(function(){
    jQuery(".menu-trigger").click(function() {
    $(".menu-trigger").hide("scale")
    jQuery(".test").slideToggle(900, function ([complete]){
    jQuery(this).toggleClass(".test").css("display");
})
});
});
    jQuery(document).ready(function(){
jQuery(".bio-button").click(function() {
jQuery(".bio-content").slideToggle(900, function ([complete]){
jQuery(this).toggleClass(".bio-content").css("display");
})
});
});
    jQuery(document).ready(function(){
jQuery(".drums-button").click(function() {
jQuery(".drums-content").slideToggle(900, function ([complete]){
jQuery(this).toggleClass(".drums-content").css("display");
})
});
});
    jQuery(document).ready(function(){
jQuery(".info-button").click(function() {
jQuery(".info-content").slideToggle(900, function ([complete]){
jQuery(this).toggleClass(".info-content").css("display");
})
});
});
    function changeImage(){
var ima = document.getElementById("BSlate");
if (ima.src.match('BIDSlate')){
(ima.src ="img/BSlate.png").fadeIn(1200);
    }
    else
(ima.src ="img/BIDSlate.png").fadeIn(1200);
    }
.bio-content{
height:400px;
background-color:rgba(255,255,255,0.5);
width:100%;
display:none;
margin:0;
padding:0;
    }
    .info-content{
height:800px;
background-color:rgba(0,0,0,0.5);
width:100%;
display:none;
margin:0;
padding:0;
    }
    .drums-content {
height:400px;
background-color:rgba(255,255,255,0.5);
width:100%;
display:none;
margin:0;
padding:0;
    }
<!-------------- MY HTML -------------------->

    <div id="menuwrapper"><!-----------MENU START------------>
<img id="BSlate" src="img/BSlate.png" style="max-width:100%" />
    </div>
    <div class="test">
    <ul>
        <li class="bio-button">Biography</li>
            <li class="info-button">Info</li>
            <li class="drums-button">Drums</li>
        </ul>
            <div class="bio-content"></div>
            <div class="info-content"></div>
            <div class="drums-content"></div>
    </div>
    <span class="menu-trigger" onclick="changeImage()"><h1 class="menu-button">MENU</h1></span><!-----------END MENU------------>


    

Answer №1

Feel free to give this a shot.. don't forget to take a look at https://jsfiddle.net/9cbr1jkm/1/

jQuery Magic

$.noConflict();
jQuery(document).ready(function(){

jQuery('.test > ul').on('click','li',function(){
    var item = jQuery(this).attr('class');
  console.log(item);

  switch(item){
  case 'bio-button':
  jQuery('.bio-content').slideToggle('slow');
  break;

  case 'info-button':
  jQuery('.info-content').slideToggle('slow');
  break;

  case 'drums-button':
  jQuery('.drums-content').slideToggle('slow');
  break;

  }
});

}); 

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

Automatically resizing images in a canvas when their resolution exceeds the canvas size in HTML5

I am currently using Html5, fabric.js, and JavaScript to upload multiple images to a canvas. However, there are instances where the uploaded image size exceeds that of the canvas. I am looking for a way to ensure that the image is set to a fixed size. v ...

Adjusting the height in AngularJS based on the number of items in a table

I've developed a straightforward AngularJS application with multiple tables on one page. In order to add scrolling functionality, I initially used a basic CSS code snippet like: tbody { overflow: auto; } I also experimented with the https://github. ...

Unexpected Error Causing Failure in jQuery Ajax Call

My jQuery ajax call is encountering an undefined error. Here is my JavaScript code snippet: $.ajax({ type: "POST", url: "Data/RealTime.ashx", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", timeout: 15000, ...

Deselect the checkbox using jQuery

How can I retrieve the value of an unselected checkbox (id) after it has been deselected? For example, when I select checkbox 1, I get a value of 1. But when I deselect checkbox 1, the value remains the same (1). Does anyone know how to solve this issue? ...

Comparison of Chrome's compatibility with Bootstrap and Edge

Firefox Safari I am facing an issue that seems obvious, but I am unable to pinpoint the exact cause. It just doesn't seem right for no apparent reason. is the website in question. I have tried various troubleshooting methods such as inspecting th ...

Automatically numbering table columns with custom language localization in JavaScript using Jquery

Is there a method to automatically number table data in a local or custom language? As a Bengali individual, I have figured out how to automatically number the first data of each row using css and js. However, I am uncertain about how to implement custom n ...

A method for automatically refreshing a webpage once it switches between specific resolutions

On my page www.redpeppermedia.in/tc24_beta/, it functions well at a resolution of over 980px. However, when the resolution is brought down to 768px, the CSS and media queries alter the layout. But upon refreshing the page at 768px, everything corrects itse ...

Acquiring Twitter updates for a dynamic Bootstrap carousel display

I've been trying to load multiple tweets from the stream into the slideshow, but I can only get one to show up. I believe it has to do with the placement of the <div id="feed"> element, but I can't seem to figure out what I'm missing. ...

access the content of a div element by its class attribute

Within the div element, a value has been set and I am attempting to retrieve this value using its class. However, the code below does not return the desired value. What mistake am I making here? How can I resolve this issue? <div title="Find on Amazo ...

Maintaining fixed panels as you scroll through a centrally aligned layout

I am looking to create a layout with three divs set up as columns. The outer two will be for navigation and need to stay in place while the user scrolls, but the middle section will contain content that should scroll normally along with the page. I know t ...

Utilizing form selectors in non-traditional elements

Trying to optimize my website by avoiding nested forms, I have multiple forms loaded via AJAX. Instead of nesting them, I plan to use select and checkbox selectors along with jQuery actions outside the form element. Here's what I have in mind: <di ...

Is there a way I can decrease the width of the input field on the left side?

body { background: white; font-family: 'Ubuntu', sans-serif; } .cas { display: inline-block; border: 2px solid #0C8346; background: #0C8346; font-weight: 300; font-size: 20px; padding: 5px; width: 200px; text-align: center; ...

Transforming an unordered list to function similarly to a select input

I am looking to style a ul list to function as a select form element. I have successfully populated a hidden input using my code. Now, I am trying to make the ul behave like a select input when either the keyboard or mouse is used. Previously, I had some ...

Create a dynamic and interactive website using a combination of jQuery and AngularJS

I recently came across an interesting tidbit on the FAQs of Angular stating that "Angular can use jQuery if it's present in your app when the application is being bootstrapped". This got me thinking, is it considered a best practice to include both j ...

Is it possible to utilize :not in this scenario?

<ul class="promocode"> <li>one</li> <li>two</li> <li class="three">three</li> </ul> Is there a way to use :not in order to apply a hover effect to the entire list, except when hovering ov ...

Steps for generating a sophisticated shadow effect using CSS

Currently in the process of revamping a poorly designed website by replacing images with CSS whenever possible, along with other updates. I have encountered a challenging graphic (there are three of these, one for each active tab): https://i.sstatic.net/1 ...

Getting all nodeName within a div tag using jQuery:

Can anyone help me figure out how to retrieve all elements' nodeName using jQuery? I've been attempting it myself, but so far I can only manage to get the nodeName of a single element. <div class="module"> <p class="aa">Lorem Ips ...

Equal vertical alignment in the center using flexbox

My flexbox layout is set up as shown in the code snippet below: html { height:100%; width:100%; } body { display:flex; flex-direction:column; align-items:stretch; height:100%; width:100%; margin:0; background-color:grey; } header { b ...

Unable to change Bootstrap variables within a Next.js project

I'm having trouble changing the primary color in Bootstrap within my NextJS project. I've tried different methods but nothing seems to work as expected. Here is the code snippet from my "globals.scss" file that I imported in "_app.js": $primary: ...

The issue of button onclick textfield validation malfunctioning

Within this container, there is a text field identified as 'codeCityId' along with a button that triggers an onclick method. When the button is clicked, the function will verify the input. function click()={ var valid = $('#codeCityId' ...