Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:09:04+00:00 2026-05-27T15:09:04+00:00

I have multiple unordered lists on my page. In each list, I want to

  • 0

I have multiple unordered lists on my page. In each list, I want to show only the first five list items by default, then have a link that toggles the display of the remaining items on and off.

I started off with this:


$("ul li").slice(5).hide();

But that ends up hiding all items in all lists except for the first five in the first list, because they all get counted together.

How can I do this but have it affect each list individually (note that I can’t add unique IDs to each list)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:09:05+00:00Added an answer on May 27, 2026 at 3:09 pm

    You would need to use the each function to do this for each and every <ul> you have. Try something like this:

    $("ul").each(function(){
      $(this).children().slice(5).hide();
    });
    

    Then use some code like this to show them all:

    $("#btn").click(function(){
       $("ul").each(function(){
          $(this).children().show();
       });
    });  
    

    Here is a jsfiddle:
    http://jsfiddle.net/F8ByE/

    Hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multiple unordered lists, with a h2 titling each list by subject.
I have multiple list items in an unordered list. Each list item looks like
I'm new to jquery and I have a page with multiple unordered lists ul.
I have multiple autocomplete inputs on my page. Behind the scenes, each autocomplete list
I have three unordered lists each containing a subset of a group of items
I have multiple forms for lots of products on my page and want to
I have a couple un-ordered lists on my page. Both lists use list-style: disc
I have the following function that fades each line of an unordered-list in and
I have code that adds list items to an unordered list, and associated with
I have multiple unordered lists with li's in the form of a radio selection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.