Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:09:42+00:00 2026-06-17T03:09:42+00:00

I am using Jquery to control the css3 transition (margin) animation of a nested

  • 0

I am using Jquery to control the css3 transition (margin) animation of a nested dropdown menu. I can get the nested menus to dropdown on click of the link that triggers the event in the main part of the menu, then if I click the same trigger again it closes the dropdown which it is supposed to do. But if I click all the dropdown triggers all the dropdowns menus are all visible at the same time.

What I am after is when I click another dropdown trigger in the same main menu, if one of the dropdowns is already open, the open one will close using css3 transition controled with Jquery as the new one opens. So only one dropdown can be open at a time.

I am new to jquery and I am aware that the jquery below is not the best way to do this. Any guidance in the right direction is much appreciated.

Jquery:

$(function() {  
    $("#drop1").click(function() {  
        $(".sub1").toggleClass("submenu");
    });  
});

$(function() {  
    $("#drop2").click(function() {  
        $(".sub2").toggleClass("submenu");
    });  
});

$(function() {  
    $("#drop3").click(function() {  
        $(".sub3").toggleClass("submenu");
    });  
});

CSS:

ul {width:100%; list-style: none; display:block;}

ul li {display:inline-block; width: 20%; height: 40px; float:left; background: #ccc; text-align:center;}

ul li a {display:block; width:100%; height: 40px; position:relative;}

.sub1, .sub2, .sub3 {width:300px; margin: -40px 0 0 0; position:absolute; z-index:-1;
transition: margin 0.2s ease; 
-moz-transition: margin 0.2s ease; 
-webkit-transition: margin 0.2s ease;
-o-transition: margin 0.2s ease;
-ms-transition: margin 0.2s ease;}

.submenu {margin:0; background: #666;}

.sub1 li, .sub2 li, .sub3 li {text-align:center; width: 33%;}

HTML:

<ul>
    <li>normal</li>
    <li><a id="drop1" href="#">drop</a>
        <ul class="sub1">
            <li>drop</li>
            <li>drop</li>
            <li>drop</li>
        </ul>
    </li>
    <li><a id="drop2" href="#">drop</a>
        <ul class="sub2">
            <li>drop</li>
            <li>drop</li>
            <li>drop</li>
        </ul>
    </li>
    <li>normal</li>
    <li><a id="drop3" href="#">drop</a>
        <ul class="sub3">
            <li>drop</li>
            <li>drop</li>
            <li>drop</li>
        </ul>
    </li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:09:44+00:00Added an answer on June 17, 2026 at 3:09 am

    I would go for a simpler solution, I hope it helps you (I have tested it).

    You will need to change a bit of your code, to make the links that activate the dropdown all members of the same class, in this case drop. For example:

    <a id="drop1" href="#" class="drop">drop</a>

    You should do that for all the dropdown selectors (#drop1, #drop2, #drop3).

    Then use this function:

    $(function() {  
        $("a.drop").click(function() {  
        $('.submenu').not( $(this).next() ).toggleClass("submenu");
            $(this).next().toggleClass("submenu");
        });  
    });
    

    What this will do is:

    1. Check if there is a submenu already in place, and if this submenu is not the current that we are clicking. This toggles again (disable submenu) every element that is not which we are clicking (because that one will be toggled in the next line). That is made in the first line of the function.
    2. Then, it will toggle the class of the current clicked element.

    We need both lines, because the menu has a state where none of the elements is showing its submenu.

    The $(this).next() is used in this case because your submenu is the next element to the clicked one; in other words, its just after the that activates the click.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the previously selected value of a dropdown control using jquery
Greetings, how to get the selectedindex of check box from checkboxlist control using jquery?
During implementing Menu control using jquery and css I got the following issue: Here
Using jQuery I'm trying to get the id of control, which I clicked (radiobutton).
How to get clientID of Datalist control using jquery , I tried using the
I am using jQuery star rating control found at http://www.fyneworks.com/jquery/star-rating/#tab-Overview . I am using
I am looking for a fancy Slider control using JQuery/Javascript. The native JQuery slider
I'm using jQuery UI's datepicker control in a position: fixed toolbar at the bottom
I am making an AJAX call using jQuery to an .ascx control's method in
I have a datepicker control setup using the JQuery UI, I am also using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.