Jquery Close/Open Multiple Toggles

Posted by Pedro on Stack Overflow See other posts from Stack Overflow or by Pedro
Published on 2010-05-15T02:39:06Z Indexed on 2010/05/15 2:44 UTC
Read the original article Hit count: 270

Filed under:

Hi, I have the toggle in my menu Working successfully for the two links that I have within it. Because the top link once toggled covers the other link, there is no problem. But since the link beneath it leaves the top link exposed, a user could click that and now have two toggled items open and pretty much stacked on top of each other. Is there a way for me to check if the other toggled item is open and if so, close it? Thanks!

<div class="parents-toggle">
 <a href="#" id="customize-toggle">Customize</a><br/>
 <div class="menu-toggle hidden" id="customize-menu">
 <div class="menu-toggle-one">
 <h3>Background</h3>
  <ul>
   <li><a href="#">Dark Wood</a></li>
   <li><a href="#">Wallpaper</a></li>
   <li><a href="#">Bricks</a></li>
   <li><a href="#">Planks</a></li>
   <li><a href="#">Default</a></li>
 </ul>
</div>     
<div class="menu-toggle-two">
 <h3>Layout</h3>
 <ul>
  <li><a href="#">Grid</a></li>
  <li><a href="#">List</a></li>
  <li><a href="#">Full</a></li>
 </ul>
</div>
</div>
</div>
<a href="/submit/">Submit video</a><br/>
<div class="parents-toggle">
 <a href="#" id="channels-toggle">Channels</a>
 <div class="menu-toggle hidden" id="channels-menu">
  <div class="menu-toggle-one">
  <ul>
   <li><a href="#">Automotive</a></li>
   <li><a href="#">Comedy</a></li>
   <li><a href="#">Movies</a></li>
   <li><a href="#">Weather</a></li>
  </ul>
 </div>
 <div class="menu-toggle-two">
  <ul>
   <li><a href="#">Business</a></li>
   <li><a href="#">Commercials</a></li>
   <li><a href="#">Music</a></li>
   <li><a href="#">Technology</a></li>
  </ul>
 </div>
</div>
</div>
</div>

<script>
 $("#customize-toggle").click(function () {
 $("#customize-menu").toggle();
 });
 $("#channels-toggle").click(function () {
 $("#channels-menu").toggle();
 });
</script>

© Stack Overflow or respective owner

Related posts about jQuery