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 6542783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:16:07+00:00 2026-05-25T11:16:07+00:00

I have created a jquery dropdown menu with the following HTML: <dl class=dropdown> <dt><a

  • 0

I have created a jquery dropdown menu with the following HTML:

<dl class="dropdown">
               <dt><a id="linkglobal1"><span class="icon lock">Action</span></a></dt>
                <dd>
                    <ul id="ulglobal1">
                        <li><a href="#"><span>Everyone</span></a></li>
                        <li><a href="#"><span>Friends</span></a></li>
                        <li><a href="#"><span>Only Me</span></a></li>
                        <li><a href="#"><span>Customize</span></a></li>
                  </ul>
               </dd>
            </dl>

and then the JS:

$(document).ready(function()
{
    $('dl.dropdown dt a').click(function()
    {
        $("dl.dropdown dt a").removeClass("selected");
        var toggleId = "#" + this.id.replace(/^link/,"ul");
        $('dl.dropdown dd ul').not(toggleId).hide();
        $(toggleId).toggle();
        if($(toggleId).css("display") == "none")
        {
            $(this).removeClass("selected");
        }
        else
        {
            $(this).addClass("selected");
        }
    });
    $("dl.dropdown dd ul li a").click(function()
    {
        $("dl.dropdown dd ul").hide();
        $("dl.dropdown dt a").removeClass("selected");
    });
    $(document).bind('click', function(e)
    {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
        {
            $("dl.dropdown dd ul").hide();
            $("dl.dropdown dt a").removeClass("selected");
        }
    });
});

The problem I am having is that it relies on using ID’s on both the <dt> link and the <ul>. How can I modify my jQuery so that it no longer relies on them?

Thanks

EDIT: I’ve answered this myself. See below.

  • 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-05-25T11:16:08+00:00Added an answer on May 25, 2026 at 11:16 am

    Did it with this:

    $(document).ready(function()
    {
        $('dl.dropdown dt a').click(function()
        {
            $("dl.dropdown dt a").removeClass("selected");
    
            var toggleMenu = $(this).parent().parent().find('dd ul');
    
            $(toggleMenu).toggle();
    
            $('dl.dropdown dd ul').not(toggleMenu).hide();
    
            if(toggleMenu.css("display") == "none")
            {
                $(this).removeClass("selected");
            }
            else
            {
                $(this).addClass("selected");
            }
        });
        $("dl.dropdown dd ul li a").click(function()
        {
            $("dl.dropdown dd ul").hide();
            $("dl.dropdown dt a").removeClass("selected");
        });
        $(document).bind('click', function(e)
        {
            var $clicked = $(e.target);
            if (! $clicked.parents().hasClass("dropdown"))
            {
                $("dl.dropdown dd ul").hide();
                $("dl.dropdown dt a").removeClass("selected");
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a dropdown menu with jquery: here Everything is ok but in
I have stolen/found/used/written and edited the following widget of jQuery for a auto-completing dropdown.
I'm using jQuery to create a simple, but large dropdown menu. I have some
I have created a drop-down-menu, the html for the drop-down part basically looks like
I have created a drop down with jQuery that can be seen here by
I have created a jQuery animation that can be seen by clicking the Preview
I have created a simple JQuery script with hovering effect on some links. The
I have created an interface using jQuery UI Tabs, however one of my requirements
I have created a dynamic list picker script using Jquery 1.3 and PHP that
I have created a great stand-alone web form in asp.net utilizing many jQuery features

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.