Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd suggest the following:</p> <pre><code>$(".tab").click(function() { var x = this.id, // equivalent to $(this).attr('id'), but slightly faster/more-simple show = $('#' + x + 'box'); if (show.length){ $('.contentBox').slideUp(500); show.slideDown(500); } });​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/Kn5vm/" rel="nofollow">JS Fiddle demo</a>.</p> <p>Or the following (equivalent to the above, but using a callback):</p> <pre><code>$(".tab").click(function() { var x = this.id, show = $('#' + x + 'box'); if (show.length){ $('.contentBox') .slideUp(500, function(){ show.slideDown(500); }); } });​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/Kn5vm/1/" rel="nofollow">JS Fiddle demo</a>.</p> <p>This assumes the following:</p> <ol> <li>That all of the 'boxes' you want to show have the class of <code>contentBox</code>,</li> <li>That the id of the 'box' you want to show takes the form of the <code>id</code> of the link that's clicked followed by the word 'box', so clicking the <code>#signup</code> link reveals <code>#signupbox</code>.</li> </ol> <hr /> <p><strong>Edited</strong> to include a CSS-only option:</p> <p>With the following HTML:</p> <pre><code>&lt;div id="container"&gt; &lt;div id="tabbox"&gt; &lt;a href="#signupbox" id="signup" class="tab signup"&gt;Signup&lt;/a&gt; &lt;!-- note the href --&gt; &lt;a href="#loginbox" id="login" class="tab select"&gt;Login&lt;/a&gt; &lt;/div&gt; &lt;div id="panel"&gt; &lt;div id="loginbox" class="contentBox"&gt;Login Form&lt;/div&gt; &lt;div id="signupbox" class="contentBox"&gt;Signup Form&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;​ </code></pre> <p>And the CSS:</p> <pre><code>.contentBox { height: 0; -webkit-transition: height 1s linear; -moz-transition: height 1s linear; -o-transition: height 1s linear; -ms-transition: height 1s linear; transition: height 1s linear; overflow: hidden; } .contentBox:target { height: 2em; -webkit-transition: height 1s linear; -moz-transition: height 1s linear; -o-transition: height 1s linear; -ms-transition: height 1s linear; transition: height 1s linear; }​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/Kn5vm/3/" rel="nofollow">JS Fiddle demo</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload