To get started, here is a method that links the examples below to how to do this in the animation you are after :
$(function() { $("#nav").delegate("li","click", function() { var newDiv = $(".box3 .content").eq($(this).index()-1); newDiv.siblings().hide().end(); // hide the others if(newDiv.is(":visible")) { // if shown, fade it out, when the fade finishes, slide everything back newDiv.fadeOut(function() { $(".box3").hide(); $(".box1, .box2").animate({ width: "50%" }); }); } else { // if not shown, then slide over space, then fade in $(".box1, .box2").animate({ width: "25%" }, function() { $(".box3").show(); newDiv.fadeIn("fast"); }); } }); });
Given your current CSS, you can do this:
$(function() { $("#nav").delegate("li a","click", function() { $(".box3").show(); $("#" + $(this).text()).show().siblings().hide(); }); });
Here's a working example , although you can see CSS, it takes a bit of work to get 100%. I suggest a few changes: provide your links and containers matching identifiers, for example:
<li><a id="ad">ADVERTISING</a></li> <div id="ad-container" class="content">ADVERTISING</div>
Then JS could be:
$(function() { $("#nav").delegate("li a","click", function() { $(".box3").show(); $("#" + this.id + "-container").show().siblings().hide(); }); });
Here is a working example of this ... it allows you to change the text as you like and not worry about breaking JS later. Another alternative is to disable the link index in the list using .index() <li> if the number of links was consistent with the <div> in all cases, even if there is an offset due to "hello!". link.
Here is an example index approach with your current HTML:
$(function() { $("#nav").delegate("li","click", function() { $(".box3").show(); $(".box3 .content").hide().eq($(this).index()-1).show(); }); });