jQuery Accordian

Posted by Fuego DeBassi on Stack Overflow See other posts from Stack Overflow or by Fuego DeBassi
Published on 2010-05-13T06:22:02Z Indexed on 2010/05/13 6:24 UTC
Read the original article Hit count: 258

Filed under:
|

Just wondering if anyone can provide some basic advice on an accordion I'm trying to simplify. Got a working version, but it seems way overly complex. Here is my new JS.

   $(document).ready(function() {
     $("#themes li ul").hide();
     $("#themes li").hover(function() {
       $("ul").show();
         }, function() {
         $("li ul").hide();
   });

The markup looks like this:

<ul>
  <li>Tier 1
    <ul>
      <li>Tier 2</li>
      <li>Tier 2</li>
    </ul>
  </li>
  <li>Tier 1
    <ul>
      <li>Tier 2</li>
      <li>Tier 2</li>
    </ul>
   </li>
</ul>

My script works alright. But it shows all of the child ul's when any parent li is hovered, and it hide's all the child ul's when unhovered. Just not sure how I can get it to A.) Only .show the li > ul when that specific li is hovered. And B.) Hide the show'n li > ul only when another one is hovered (not itself). Example + explanation would be especially helpful! Thanks!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about accordion