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:
- $(document).ready(function() {
-
- $(".div1, .div2, .div3, .div4, .div5, .div6, .div7").hide();
- $(".link1, .link2, .link3, .link4, .link5, .link6, .link7").bind("click", function () {
- $(".div1, .div2, .div3, .div4, .div5, .div6, .div7").fadeOut();
-
- if ($(this).attr("class") == "link1")
- {
- $(".div1").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link2")
- {
- $(".div2").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link3")
- {
- $(".div3").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link4")
- {
- $(".div4").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link5")
- {
- $(".div5").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link6")
- {
- $(".div6").delay(400).fadeIn();
- }
- else if ($(this).attr("class") == "link7")
- {
- $(".div7").delay(400).fadeIn();
- }
- });
- });
I have an alternative for this, and that is :
- $('#menu a').click(function (e) {
- hideContentDivs();
- var tmp_div = $(this).parent().index();
- var main= $('#content div').eq(tmp_div).delay(500).fadeIn();
- });
- function hideContentDivs() {
- $('#content div').each(function () {
- $(this).fadeOut();
- });
- }
- 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?