Require presenting only four lists - slideDown in jQuery

I am trying to display only 4 out of 8 lists initially, and upon clicking a "more" button, the rest of the list should be revealed. Can someone please assist me with this?

Below is the jQuery code:

$(document).ready(function() {
  $("#accordion").hide();
  $('#acc').click(function() {
    if ($("#accordion").is(":hidden")) {
    $("#accordion").slideDown("fast");
    } 
    else {  $("#accordion").hide(); }       
  });
})  ;

And here is the HTML code:

<div>
<h1 style="font-size:12px;"  id="acc">Product</h1>
<div id="accordion">
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
<li>Link5</li>
<li>Link6</li>
<li>Link7</li>
<li>Link8</li>
</ul>
<span id="more"><a href="#">More</a></span>
</div>
</div>

Answer №1

You have found the solution you were seeking

$(document).ready(function() {
  $("#accordion").hide().find("li:gt(3)").hide();

  $('#acc').click(function() {
    if ($("#accordion").is(":hidden")) {
    $("#accordion").slideDown("fast");
    } 
    else {  $("#accordion").hide(); }       
  });

  $("#more").click(function(){
    $(this).remove();
    $("#accordion li").show();
  });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choosing options from a drop-down menu based on the selection of a radio button with ever-changing

I have a dynamic form with fields retrieved from a database. This form features questions and answers. My goal is to display a number, such as 5, in a drop-down question based on the selected radio button for question 3 without needing to submit the form ...

The initial navigation pill content failed to display in Bootstrap

I am experiencing an issue with my pills that have 4 tabs. Initially, when I reload the page, the content of the first tab does not show up. However, if I navigate to another tab and then back to the first tab, the content appears. Can anyone suggest a fix ...

What are some effective methods for testing web applications on mobile devices?

While I may not have the funds to purchase mobile phones and iPhones, I am eager to ensure my web applications can be accessed on mobile devices. Are there any software solutions available to simulate these devices, or what steps should I take? ...

Using Selenium to scroll down to an element until its 'style' changes

I'm in the process of scraping a review page similar to this one. While this specific page has only a few reviews, there are others with a larger volume that require extensive scrolling. Upon observation, I noticed that when the page is not complete ...

Deleting Data with HTML Using the HTTP DELETE Method

I've encountered an issue with making HTTP DELETE requests in webapp2. Currently, I've resorted to using a different URI with GET method as a temporary workaround. However, I'd prefer to implement a more RESTful approach. Upon inspecting th ...

Ways to attach an item using its lower point instead of its upper coordinate

I am currently working on a poker table project using React. As of now, I have player components that need to be strategically positioned around the table. https://i.sstatic.net/gX9Ij.png One challenge I'm facing is that when the screen attribute ch ...

Issues arising from the interaction of one DIV with another DIV

I'm having trouble positioning a menu (height = 100%) next to the logo. Essentially, when the image controls the height of the DIV (container), it seems logical that adding another DIV (menu) with height: 100% inside that DIV (container) should resul ...

Transferring form data to an external webpage and fetching the HTML response from the server

Is it possible to retrieve the HTML or plain text from the result of a form sent to an external page? I have a form that sends variables to an external server and the result goes to an iframe. How can I retrieve the HTML or text from the iframe? I'm ...

Steps for closing a Bootstrap 4 Pop-up using the X button alongside a carousel

I need help with closing a Bootstrap 4 pop-up only when the X icon is clicked. If I remove the 'data-backdrop="static"' code, the pop-up closes whenever I click outside the modal, but this is not ideal as it would also close when trying to intera ...

Exploring the internet and its elements through DOM using getElementById

When using Internet Explorer 8, I encountered an issue where the getElementById method does not return DOM elements but plain elements when trying to copy a Div from a parent window to a pop-up. As a result, calling appendChild on those types of items resu ...

Unexpected Type Error: Unable to Assign 'Render' Property to Undefined

At the moment, I am encountering these specific issues: An Uncaught TypeError: Cannot set property 'render' of undefined The element #main cannot be found This is the code that I currently have. Despite looking for solutions from various sourc ...

Send a variety of jQuery element selectors to a function

myFunc() is connected to the document scroll event, resulting in frequent calls. To optimize performance, I intend to store HTML selections in variables and then pass them to the function. However, upon running the code snippet below, an error appears in t ...

Animate a nested element dynamically with jQuery

Whenever I click on the "view" button, I am dynamically adding data to a div. This feature is working perfectly fine. However, I wanted to improve it by adding another nested dynamic element. The problem I'm facing now is that when I try to expand al ...

The page layout is completely messed up due to the floating right button

In my jQuery v3.3.1 / Bootstrap v4.1.2 application, I am attempting to add a button at the top right of the page. Please visit for credentials [email protected] 111111 The code I am using is as follows: <section class="card-body content_block_ad ...

Ways to utilize a single HTML page for various URLs while changing one variable value based on the queried URL

My current HTML page structure looks like this: <body ng-controller="DashboardDisplay" onload="submit()"> <div class="container-fluid" > {{scope.arr}} </div> </body> <script> var myApp = angular.module(&apos ...

Resize the tab header in primefaces to fit your needs

Is there a way to change the height of the tabView's header specifically in primefaces? Take for instance the tabs with headers like "God Father I", "God Father II" on this link, I only want to adjust the height of the header and not the entire tab. ...

Determine the exact beginning and ending positions of a word when dividing it using Javascript

After creating a special function that breaks down a word based on spaces while keeping punctuation marks intact, I was able to achieve the desired result. function tokenizeUtterance( utterance ) { let spilittedUserText = utterance.toString().match( /[& ...

How come the method $.when().pipe().then() is functioning properly while $.when().then().then() is not working as expected

I'm still grappling with the concept of using JQuery's Deferred objects, and am faced with a puzzling issue. In this code snippet, my attempt to chain deferred.then() was unsuccessful as all three functions executed simultaneously. It wasn't ...

Creating a dynamic JSTree that loads data on demand using Stored Procedures

Currently in my SQL Server database, I have two Stored Procedures that are responsible for extracting data from a tree structure: One procedure retrieves all nodes at a specific level based on the provided level number. The other procedure retrieves th ...

I aim to generate a JavaScript string that, when placed within a div tag, will display as a list

I need assistance with formatting a string that contains a list of items to display in a specific way within a div tag using JavaScript. The string has multiple items that I wish to show as a bulleted list. Here is an example of the string: const items = & ...