Grow your CSS skills. Land your dream job.

Last updated on:

Display Only First X Divs, Toggle Rest

var news = 2;
hidenews = "- Hide news archive";
shownews = "+ Show news archive";

$(".archive").html( shownews );

$(".archive").click(function (e) {
       if ($(".news:eq("+news+")").is(":hidden")) {
           $(".archive").html( hidenews );
       } else {
           $(".archive").html( shownews );


<div class="news">First news</div>
<div class="news">Second news</div>
<div class="news">Third news</div>
<a class="archive" href="#"></a>

Reference URL


  1. Permalink to comment#

    sweet, thank you!

  2. Permalink to comment#

    Excellent, thanks for this =)

  3. Sorry, the reference URL has not been available for a long time. It’s fixed now!

  4. sdf
    Permalink to comment#

    first post sample piece of code.

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".