Difficulty with JQuery Show and Hide Functionality

I've implemented a jQuery menu, but encountering the issue where clicking on any menu link opens all menus instead of just the one clicked. I've attempted to resolve this by using show and hide classes, however, it seems that nothing is working now. The desired behavior should be that when clicking on a link, only that specific menu should open while others remain closed. Can someone please assist me in troubleshooting this problem? I can't seem to pinpoint where I'm going wrong as there are no console errors showing up in the browser.

Here's my code snippet:

...

Answer №1

Below is the revised code based on your requirements. Take a look and let me know if this meets your needs.

$(document).ready(function() {
  $("#section-1").click(function() {
    $("#drop-1").slideToggle();
  });
  $("#section-2").click(function() {
    $("#drop-2").slideToggle();
  });
});
.application-container {
  position: relative;
}


/* The dropup container */
.dropup {
  float: left;
  overflow: hidden;
  position: initial;
  display: none;
}


/* Dropup content (hidden by default) */
.dropup-content {
  width: 100%;
  bottom: -100%;
  left: 0%;
  position: absolute;
  background-color: #f9f9f9;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: -1;
}
<body>
  <div class="container application-container">
    <div class="row seven-rows">
      <div class="column text-center image-container" style="background-color: red" id="section-1">
        <img src="./images/aoe_icons_services_order_management.png" width='69' height='61' alt="e-commerce">
        <p class="mt-2 text-custom">E Commerce</p>
      </div>
      <div class="dropup show" id="drop-1">
        <div class="dropup-content pt-4 pb-4">
          <div class="row">
            <div class="col-lg-8 ml-5">
              <h3> Innovative Omnichannel E-Commerce Solutions</h3>
              <p>AOE develops flexible and high-performance Enterprise E-Commerce portals. Our solutions digitize business processes and create efficient, profitable platforms for providers and customers.</p>
              <a class="btn btn-custom">E Commerce Solutions</a>
            </div>
            <div class="col-lg-4">

            </div>
          </div>
        </div>
      </div>
      <div class="column text-center image-container" id="section-2">
        <img src="./images/aoe_icons_webportal.png" width='69' height='61' alt="web portals">
        <p class="mt-2 text-custom">Web Portals</p>
      </div>
      <div class="dropup show" id="drop-2">
        <div class="dropup-content">
          <div class="header">
            <h2>Mega Menu</h2>
          </div>
          <div class="row">
            <div class="col-lg-8">
              <h3>Category 1</h3>
              <a href="#">Link 1</a>
              <a href="#">Link 2</a>
              <a href="#">Link 3</a>
            </div>
            <div class="col-lg-4">
              <h3>Category 2</h3>
              <a href="#">Link 1</a>
              <a href="#">Link 2</a>
              <a href="#">Link 3</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>

Answer №2

If you desire the first item to be visible when the page loads, simply add the class show to the first dropup: <div class="dropup show">. If you prefer both dropups to remain invisible until <image-container> is clicked, use: <div class="dropup">:

I trust that I have correctly understood your requirements and that this solution meets your needs:

$(document).ready(function () {
      $(".image-container").on('click', function () {
        var delayTime = 250;
        var $dropup = $(this).next(".dropup");
        if($dropup.is(':visible')){
          $dropup.delay(delayTime).slideUp(200);
        } else {
          $dropup.delay(delayTime).slideDown(200);
        }
        $(".dropup").hide();
      });
    });
.application-container{
    position: relative;
  }
/* The dropup container */
.dropup{
  float: left;
  overflow: hidden;
  position: initial;
  display: none;
}

.dropup.show {
  display: block;
}

/* Dropup content (hidden by default) */
.dropup-content {
  
  width:100%;
  bottom:-100%;
  left:0%;
  position: absolute;
  background-color: #f9f9f9;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: -1;
}
<div class="container application-container">
    <div class="row seven-rows">
      <div class="column text-center image-container">
        <img src="http://lorempixel.com/69/61/" width='69' height='61' alt="e-commerce">
        <p class="mt-2 text-custom">E Commerce</p>
      </div>
      <div class="dropup show">
        <div class="dropup-content pt-4 pb-4">
          <div class="row">
            <div class="col-lg-8 ml-5">
              <h3> Innovative Omnichannel E-Commerce Solutions</h3>
              <p>AOE develops flexible and high-performance Enterprise E-Commerce portals. Our solutions digitize business
                processes and create efficient, profitable platforms for providers and customers.</p>
              <a class="btn btn-custom">E Commerce Solutions</a>
            </div>
            <div class="col-lg-4">

            </div>
          </div>
        </div>
      </div>
      <div class="column text-center image-container">
        <img src="http://lorempixel.com/69/61/" width='69' height='61' alt="web portals">
        <p class="mt-2 text-custom">Web Portals</p>
      </div>
      <div class="dropup">
        <div class="dropup-content">
          <div class="header">
            <h2>Mega Menu</h2>
          </div>
          <div class="row">
            <div class="col-lg-8">
              <h3>Category 1</h3>
              <a href="#">Link 1</a>
              <a href="#">Link 2</a>
              <a href="#">Link 3</a>
            </div>
            <div class="col-lg-4">
              <h3>Category 2</h3>
              <a href="#">Link 1</a>
              <a href="#">Link 2</a>
              <a href="#">Link 3</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>

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

What could be the reason my SVG images are not displaying?

My website contains SVGs that are not loading consistently. I acquired some from freeicons/icon8 and created a couple using Inkscape. Initially, I inserted them using HTML but switched to CSS after doing research online on how to ensure they load properly ...

Radio button - arranging the background image and text in alignment

I'm struggling to align my custom radio buttons alongside text. Here is an example image: Despite using CSS for styling, I am unable to properly align the radio buttons. Below is a snippet of my HTML: label.item { display: inline-block; positi ...

Does the CSS file load multiple times if it is being used on multiple pages?

I have a question regarding website performance. I am in the process of creating a 7-8 page website with a common CSS file used throughout. My concern is whether this CSS file will get loaded from the server every time I navigate to a new page, or if it ...

PHP AJAX POST not functioning as expected

Can someone please help me with my AJAX code issue? I've created many posts before, so I'm confused about why this one isn't working. Here is the code: $(function() { $("#btnSubmit").click(function(event) { event.preventDefault(); ...

When a new entry is added to the database, automatically refresh a <div> section within an HTML document

I have a basic webpage that showcases various products stored in the database. My goal is to implement an updater feature where, if a user adds a new product, the page will automatically display the latest addition in a specific div. I attempted to refere ...

Efficient arrow function usage in jQuery map functionality

Looking to implement an arrow function in jQuery's map function. However, after trying the following code snippet, titlesText ends up being the correct length but with empty strings: let titles = $(panelBody).find('h4'); let titlesText = $(t ...

The function replace does not exist in t(…)trim

I encountered an error in my code that breaks the functionality when checked using console.log. var map = L.map('map').setView([0, 0], 2); <?php $classesForCountries = []; if (have_posts()) : while (have_posts()) : the_post(); ...

Firefox not responding to mouse movements

I am experimenting with creating an "animation" using JavaScript's "mousemove" Check it out here This is the code I am currently using $("body").mousemove(function(e){ var wWidth = $("body").width()/2 var wHeight = $("body").height()/2 var posX; v ...

The download attribute is not functioning properly on both Chrome and Edge browsers

I've been trying to use the download attribute, but it doesn't seem to be working. I have also attempted to use the target attribute to see if there are any issues with downloading from the server or from a web (https) source. Unfortunately, noth ...

Ensure a form is validated using an onclick event with AJAX jQuery in a CakePHP framework

I am encountering an issue with validating a form on onclick event. The form I am using does not have any button or submit event. Instead of a button, I am using <a>, so how can I handle .valide() when the user clicks on an <a> </a> tag? ...

Using jQuery to remove the td element from an HTML table

Hello everyone, I have a query. I am trying to remove a specific td from a table using JavaScript, but the remove() function is not working. Here is my code: $('.btnEliminarLicencia').off('click'); $('.btnEliminarLicencia&apo ...

Is there a way to keep the header frozen while loading page content during postback?

Currently, I am working with asp.net and c#.net to develop a website. My goal is to create a content navigation system similar to what Microsoft has implemented on their Windows website: Microsoft Windows On this link, users can navigate through page cont ...

Press the button to duplicate the cell column separated by commas

In my HTML table, there is a specific column filled with container numbers that I want to copy to the clipboard when a button is clicked. The column has the class ".container" Here is the code I have been working on. HTML: <button onclick="copyToC ...

Is the CSS selector '.my-class *:not(input[type="text"])' accurate?

Is there a way to target all elements inside the DOM element with class "my-class" except for input elements of type text? I tried using the following CSS selector: .my-class *:not(input[type="text"]) { // Some CSS properties here } However, this do ...

Photo Collection: Incorporating Images

I am currently working on a project to create a photo gallery and I am facing an issue with adding photos. The user should be able to browse for a picture and enter a title for it on a page. Both the image path and title need to be saved in an XML file fro ...

Tips for styling row headers in Vaadin with CSS

I am in need of assistance with a problem I am facing. Recently, I started learning the Vaadin framework and I am trying to apply CSS to the row headers (first cell of each row), but so far I have not had any success. Below is the code that I have been usi ...

`CSS border issues`

I am currently attempting to create a square consisting of 4 smaller squares inside, but I have been facing challenges with the method I was using. Here is the code snippet: #grandbox { position: absolute; width: 204px; height: 204px; border: so ...

Tips for vertically centering elements in the header using flexbox

Within the header of my website, I have structured 3 separate divs - one for a logo, one for a search input, and one for a cart link. My goal is to align these 3 .col-md-4 divs in a vertically centered position. While these divs currently have an align-it ...

What is the correct way to display or hide a button based on my specific situation?

Creating a 'show more' button for my app has presented me with a challenge. I am using a directive to handle actions when the user clicks on the read more button: (function(window, angular) { var app = angular.module('myApp'); ...

When the JQuery event-listener for .show('drop', 500) has completed execution

Currently on the lookout for an event listener that can be used to verify when the animation using .show('drop', 500) has completed. The desired usage would be as follows: if($('#id').show('drop', 500) == complete){ // perfo ...