views:

31

answers:

1

I am using the Accordion menu to filter a data table. The menu contains two filters, with multiple options under each. You can only have ONE filter selected at a time. If you click between the two options under the first filter, the style class, 'selected' is added and removed without a problem. If you click an option under the second filter though, it DOESN'T remove the 'selected' class from the first filter. Any help would be appreciated. Thank you.

<script src="http://code.jquery.com/jquery-1.4.2.js" type="text/javascript"></script>
<script src="http://jquery.bassistance.de/accordion/jquery.accordion.js" type="text/javascript"></script>


<div>
<script type="text/javascript">
// <![CDATA[
jQuery.noConflict();
jQuery(document).ready(function(){
    jQuery('#navigation').accordion({active: 'h3.selected', header: 'h3.head', autoheight: false, });
    jQuery('.xtraMenu').accordion({active: 'h4.selected',header: 'h4.head', autoheight: false, });

});
// ]]>
</script>

<style type="text/css">
h3, h4 {font-weight: normal}
h3.selected, h4.selected {font-weight:bold;}
</style>
<ul class="basic" id="navigation">
<li>
  <h3 class="head"><a href="">Filter by Organization</a></h3>
  <ul>
    <li>
      <ul class="xtraMenu basic">
        <li>
          <h4 class="head"><a href="">Association</a></h4>
        </li>
        <li>
          <h4 class="head"><a href="">Business</a></h4>
        </li>
      </ul>
    </li>
  </ul>
</li>
<li>
  <h3 class="head"><a href="">Filter by Type</a></h3>
  <ul>
    <li>
      <ul class="xtraMenu basic">
        <li>
          <h4 class="head"><a href="">Basic</a></h4>
        </li>
        <li>
          <h4 class="head"><a href="">Advanced</a></h4>
        </li>
      </ul>
    </li>
  </ul>
</li>
</ul>
</div>
A: 

Try using the change event for the second filter to remove the 'selected' class of the first filter.

jQuery( ".xtraMenu" ).accordion({
   active: 'h4.selected',
   header: 'h4.head',
   autoheight: false,
   change: function() {
       jQuery("#navigation > h3").each(function() {
           jQuery(this).removeClass('selected');
       });
   }
});
Dieseltime
I could not get that snippet of code to work with my code on test page. Also, I am trying to remove the 'selected' class from the h4 submenu links, not the h3 'Filter by' header links.The desired functionality only allow the accordion menu to have one h4.selected at a time. That works when clicking between links under one filter, but once you click a link in a second filter, the 'selected' class is not removed from the previously selected h4 link.
mheppler9d
Use case:-open 'Filter by Organization' and click 'Association', the link bold to designate that it has been selected, then click 'Business', and now it is bold to show it has been selected and the previous link is no longer- now open the 'Filter by Type' and click 'Basic', the link bold to designate that it has been selected- if you now go back and open 'Filter by Organization', the link 'Business' is still bold, while 'Basic' is also bold, in the second filter- the issue is that 'Business' and 'Bold', can not be bold at the same time
mheppler9d