How do I shorten up this overly long JavaScript function?
<p>I have a simple script that selects a class's  and adds a class of selected to it and remove it from all other 's with the similar class.  It all works perfectly, but I know that there has to be a better way to write this out, I just can't figure it out.. Does it involve something like this?</p>

<pre><code>$('.adv-option-set a, .adv-option-set2 a, .adv-option-set3 a, .adv-option-set4 a, .adv-option-set5 a, .adv-option-set6 a, .adv-option-set7 a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set a').removeClass('selected');
        $(this).addClass('selected');
    }

    {
        $('.adv-option-set2 a').removeClass('selected');
        $(this).addClass('selected');
    }

    {
        $('.adv-option-set3 a').removeClass('selected');
        $(this).addClass('selected');
    }
});
</code></pre>

<p>So here is the code that I currently have and is working:</p>

<pre><code>$('.adv-option-set a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set a').removeClass('selected');
        $(this).addClass('selected');
    }
});

$('.adv-option-set2 a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set2 a').removeClass('selected');
        $(this).addClass('selected');
    }
});

$('.adv-option-set3 a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set3 a').removeClass('selected');
        $(this).addClass('selected');
    }
});
</code></pre>

<p>Etc. up until '.adv-option-set7 a'</p>

<p>EDITED to show the DOM:</p>

<pre><code>      &lt;article id="filter"&gt;
        &lt;ul id="filter-nav" class="option-set"&gt;
          &lt;li&gt;Filter: &lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="*" data-subid="all" class="selected"&gt;All&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="tubs-and-showers" data-subid="tubs-and-showers"&gt;Tubs &amp;amp; Showers&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="countertops" data-subid="countertops"&gt;Countertops&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="faucets" data-subid="faucets"&gt;&lt;s&gt;Faucets&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="cabinetry" data-subid="cabinetry"&gt;&lt;s&gt;Cabinetry&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="flooring" data-subid="flooring"&gt;&lt;s&gt;Flooring&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="toilets" data-subid="toilets"&gt;&lt;s&gt;Toilets&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a data-categories="accessories" data-subid="accessories"&gt;&lt;s&gt;Accessories&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
        &lt;div id="advfilter" class="advfilter filter-nav hidden"&gt;
          &lt;ul id="tubs-and-showers" class="adv-option-set1"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="modular"&gt;Modular&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="custom"&gt;Custom&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="countertops" class="adv-option-set2"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="marble"&gt;Marble&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="solid-surface"&gt;Solid Surface&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="laminate"&gt;&lt;s&gt;Laminate&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories="granite"&gt;&lt;s&gt;Granite&lt;/s&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="faucets" class="adv-option-set3"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="cabinetry" class="adv-option-set4"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="flooring" class="adv-option-set5"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="toilets" class="adv-option-set6"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul id="accessories" class="adv-option-set7"&gt;
            &lt;li&gt;&lt;span class="small"&gt;ADV&lt;/span&gt; Filter: &lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a data-categories=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
      &lt;/article&gt;
</code></pre>

<p>FINAL EDIT: This is the other part of the JS code that I have, it seems that your answers actually take this part into effect aswell though:</p>

<pre><code>    $("#advfilter ul").hide();
    $('.option-set a').on('click', function() {
        $("#advfilter ul").hide();
        $("#advfilter").removeClass('hidden');
        $("#" + $(this).attr('data-subid')).show();
        /*location.href='#filter'*/
    });

    $('.option-set a').click(function()
    {
        // if clicked item is selected then deselect it
        if ($(this).hasClass('selected'))
        {
           $('.adv-option-set1 a').removeClass('selected');
           $('.adv-option-set2 a').removeClass('selected');
           $('.adv-option-set3 a').removeClass('selected');
           $('.adv-option-set4 a').removeClass('selected');
           $('.adv-option-set5 a').removeClass('selected');
           $('.adv-option-set6 a').removeClass('selected');
           $('.adv-option-set7 a').removeClass('selected');
        }

        // otherwise deselect all and select just this one
        else
        {
           $('.option-set a').removeClass('selected');
           $(this).addClass('selected');
           $('.adv-option-set1 a').removeClass('selected');
           $('.adv-option-set2 a').removeClass('selected');
           $('.adv-option-set3 a').removeClass('selected');
           $('.adv-option-set4 a').removeClass('selected');
           $('.adv-option-set5 a').removeClass('selected');
           $('.adv-option-set6 a').removeClass('selected');
           $('.adv-option-set7 a').removeClass('selected');
        }
    });
</code></pre>
