jQuery dropdown menus
<p>I have created a jquery dropdown menu with the following HTML:</p>

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

<p>and then the JS:</p>

<pre><code>$(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");
        }
    });
});
</code></pre>

<p>The problem I am having is that it relies on using ID's on both the <code>&lt;dt&gt;</code> link and the <code>&lt;ul&gt;</code>. How can I modify my jQuery so that it no longer relies on them?</p>

<p>Thanks</p>

<p><strong>EDIT: I've answered this myself. See below.</strong></p>
