Trouble trying to simplify my code...

Trouble trying to simplify my code...

Hey there,

I wrote a code that is quite long for it's purpose, that it does is hides all the divs with the class: div1, div2....div7 and fades the in when click the link with class: link1, link2....link7...and my code fot this is:

  1. $(document).ready(function() {
  2.  
  3.    $(".div1, .div2, .div3, .div4, .div5, .div6, .div7").hide();
  4.    $(".link1, .link2, .link3, .link4, .link5, .link6, .link7").bind("click", function () {

  5.       $(".div1, .div2, .div3, .div4, .div5, .div6, .div7").fadeOut();
  6.         
  7.       if ($(this).attr("class") == "link1")
  8.       { 
  9.         $(".div1").delay(400).fadeIn();
  10.       }
  11.       else if ($(this).attr("class") == "link2")
  12.       { 
  13.         $(".div2").delay(400).fadeIn();
  14.       }
  15.       else if ($(this).attr("class") == "link3")
  16.       { 
  17.         $(".div3").delay(400).fadeIn();
  18.       }
  19.  else if ($(this).attr("class") == "link4")
  20.       { 
  21.         $(".div4").delay(400).fadeIn();
  22.       }
  23.  else if ($(this).attr("class") == "link5")
  24.       { 
  25.         $(".div5").delay(400).fadeIn();
  26.       }
  27.  else if ($(this).attr("class") == "link6")
  28.       { 
  29.         $(".div6").delay(400).fadeIn();
  30.       }
  31.  else if ($(this).attr("class") == "link7")
  32.       { 
  33.         $(".div7").delay(400).fadeIn();
  34.       }
  35.     });
  36. });
I have an alternative for this, and that is :

  1. $('#menu a').click(function (e) {
  2.     hideContentDivs();
  3.     var tmp_div = $(this).parent().index();
  4.    var main= $('#content div').eq(tmp_div).delay(500).fadeIn();
  5. });

  6. function hideContentDivs() {
  7.     $('#content div').each(function () {
  8.         $(this).fadeOut();
  9.     });
  10. }
  11. hideContentDivs();
But this won't work either because this only attributes the first div from #content to the first link from #menu , and so on, and the reason why this won't work is cause of my sorting script, I have wrote a alphabetical sorting script for my menu and that breaks the order...

Any help?