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

Having trouble loading xml/xsl files on IE11? Consider enabling compatibility mode to ensure smooth rendering on your xml/xsl page

On my website, I have a page that displays XML from an XSL document. Strangely, it works perfectly on IE8 but not on IE11 - the page appears blank even though the XML is present when viewing the source. Interestingly, if I enable compatibility mode for the ...

Using Ajax to invoke a C# webmethod

I'm trying to call a webmethod defined in this specific class <%@ WebService Language="C#" Class="emt7anReyady.myService" %> using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Linq; usi ...

The selected jQuery plugin is not functioning properly within CodeIgniter framework

I recently downloaded the jQuery Chosen plugin to use the simple "multiselect" version on my website. I followed all the necessary steps and even copied and pasted the code into CodeIgniter. Despite my experience with jQuery, I am facing an issue where the ...

The functionality of the Bootstrap tabbed pane is not functioning correctly

I am currently in the process of creating a modal tabbed pane in bootstrap following the instructions provided in this guide. You can view the code and functionality on this fiddle. $(document).on("click","#tabs a",function(event) { alert("!!!"); ...

Tips for confining a float within a div with fluctuating space

I have a scenario where I have multiple divs ('group') containing text, and there is a floated div ('toggle') in the bottom corner. The current code works well if the text length in 'group' is consistent, but the position of t ...

Can you provide an alternative code to access an element with the id of 'something' using vanilla JavaScript instead of jQuery's $('#something') syntax

Why am I seeing different console output for $('#list') and document.getElementById("list")? Here is the console printout: console.log($('#list')); console.log(document.getElementById("list")); However, the actual output in the cons ...

What is the best way to ensure the header spans the entire width of a webpage using the display: flex; property and flex-direction: column styling within the body element

Click here for the CSS code snippet Hello everyone, this is my very first query on Stack Overflow. I know it might be a simple question but it's my first time posting here so kindly bear with me. Below is the CSS code snippet provided: *{ ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

Understanding the process of retrieving the value of an element produced in a PHP foreach loop

I am faced with an issue in my code where elements are being generated within a for loop using PHP. Here is the snippet of the code: for($i=0; $i < $count; $i++) { $member = $my_array[$i]; <td><span id="myspan"><input type="text" id= ...

Using jQuery Ajax and PHP for Secure User Authentication

Hello everyone, I could really use some assistance right now. The issue I'm facing is that the error div is not showing the content I expect in the success function of my AJAX request. I've tried alerting the response, which returns true if the ...

The issue arises when trying to use jQuery post with dynamically generated variables

Hello there! I have a working jQuery post function, but unfortunately it's not behaving exactly as I hoped. In my code snippet below, the variable "url" should match a specific regex pattern and then trigger a request using jQuery to my PHP file with ...

Datatables encounters issues loading 70,000 records into the system

I have a jQuery datatable that is supposed to load over 70K records. However, the datatable fails to display anything beyond 20K records. Despite trying to use the deferRender option as a workaround, it doesn't seem to be effective. $.ajax({ ur ...

Clicking on a new tab causes the page to quickly scroll back to the top (jQuery Tabs

Currently, my website is utilizing jQuery tabs with AJAX functionality. Here is the HTML code: <div id="tabs"> <ul> <li><a id='tab-1' href="/get-1.htm">1</a></li> <li><a id=' ...

Can you provide instructions on how to insert a hyperlink onto a background image?

Is it possible to add a hyperlink to this background image without causing it to disappear? Would creating a new class in the stylesheet be the way to go? (I encountered an issue where the image disappeared when trying to call the new class). body{ back ...

Is it possible to decrease the size of a div by scrolling both vertically and horizontally?

Can a div's height and width both be reduced at the same time while scrolling down a page? Let's say that as the user scrolls, the size of the div changes from 400px by 400px to 200px by 200px, all while remaining centered on the page. I've ...

The pesky bug in my jQuery checkbox feature

Having trouble resolving a bug where unchecking the square, then red, and rechecking red brings back the red square. Need help preventing any unchecked shapes from being added back when the user toggles colors. My actual project involves many more checkbo ...

Arranging elements in a Material-UI card in a horizontal layout

I am currently working on designing a user profile display. I want to create a card layout that showcases the details listed below. My goal is to have these items displayed side by side instead of being divided as shown in the image. Despite trying to giv ...

"Blank Canvas: Exploring the Void in Laravel Blade Templates

This is the route that I am using Route::get('login', function(){ return View::make('admins.login'); }); In this code, I have created a admins/login.blade.php file to handle the login view. <!doctype html> <html> < ...

Fixing the Overflow Property in CSS

I just started learning about css, and I've encountered a problem with the code for the overflow property: div.hidden { background-color: #00FF00; width: 1000px; height: 1000px; overflow: hide; } ...

Effortlessly Transform HTML into Plain Text Using jQuery

If I wanted to create a feature on my website where users can input text into a text area and then convert it to HTML by clicking a button, how could I achieve that? I'm looking for functionality similar to what Wordpress offers, where users can enter ...