Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Show more / Show less ul li using Zepto JS Libray

Using zepto.js (v1.2.0), how can you show X items from a ul, hide the rest and show them only when the user clicks the "show more" Link/button?

I have tried the following code but not worked.

HTML:

<ul class="collapsed">
    <li>Option 1</li>
    <li>Option 2</li>
    <li>Option 3</li>
    <li>Option 4</li>
    <li>Option 5</li>
    <li>Option 6</li>
    <li>Option 7</li>
</ul>
<button type="button" class="show-more">Show more</button>

CSS:

/* show only the first 3 list items */
ul.collapsed li:nth-child(n+4) {
    display: none;
}

JS:

var $list = $(ul.collapsed); // initially the list is collapsed

// use a show-more link to toggle display of remaining items
$("button.show-more").click(function(){

    // get the current state of the list by querying the className
    var shouldShow = $list.hasClass("collapsed") == true;
    $list.toggleClass("collapsed");

    // set the link text according to the task (show or hide)
    $(this).html(shouldShow ? "Show less" : "Show more");

    // its a link, don't follow it
    return false;
});

HTML:

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!