Show / Hide for multiple Divs

Show / Hide for multiple Divs

Hi,

Sorry if I am treading on old ground but I am new to jquery. I have a page with 3 divs and 3 anchors. I am trying to build this page that loads with all 3 divs hidden, then when someone clicks on the first anchor div 1 displays. If they click the 2nd anchor then div 1 hides and div 2 shows and so on. What is the best way to do this? My code below half works, but it forces the divs that are already hidden to hide again (which looks stupid).

Thoughts from the pros out there?

  1. <!DOCTYPE html>
  2. <html>
  3. <head>

  4.  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  5. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  6.   
  7. </head>
  8. <body>

  9.   <a href="#" id="1">Lemon</a>
  10.   <a href="#" id="2">Lime</a>
  11.  <a href="#" id="3">Lime</a>

  12. <div style="height:300px;">

  13. <div id="lemon" style="width:400px;height:200px;background-color:red; display:none;">Lemongrass</div> 
  14. <div id="lime" style="width:400px;height:200px;background-color:green; display:none;">Lime</div>
  15. <div id="bitters" style="width:400px;height:200px;background-color:green; display:none;">Bitters</div>

  16. </div>


  17. <script>

  18. $(document).ready(function() { 
  19.    //add the click event to each element with the toggle class 
  20.    $('.toggle').click(function(){ 
  21.       // change the visibility of the elements with a class name that matches the title
  22.       $('.'+$(this).attr('title')).toggle();
  23.    });
  24.  })

  25. <!--<script>

  26.     $("#1").click(function () {
  27.       $("#lime").hide("clip", { }, 1000);
  28. $("#bitters").hide("clip", { }, 1000);
  29. $("#lemon").show("clip", { }, 1000);
  30.    });    

  31.     $("#2").click(function () {
  32.       $("#lemon").hide("clip", { }, 1000);
  33. $("#bitters").hide("clip", { }, 1000);
  34. $("#lime").show("clip", { }, 1000);

  35.     });    

  36.     $("#2").click(function () {
  37.       $("#bitters").hide("clip", { }, 1000);
  38. $("#lemon").hide("clip", { }, 1000);
  39. $("#lime").show("clip", { }, 1000);

  40.     });    


  41. </script>-->

  42. </body>
  43. </html>