Load Content and List on Click Load More Button Javascript, HTML, CSS

If you have too much content or a huge list and wanted to show it in smaller so that can be load on user click here is how you can do this. Below is small tutorial which allow you to do this using HTML and JavaScript and CSS for styling and look good. We also add buttons to our code. Dropdown menu and open list will be created.

First Create a Content or list

<div id="myList">
 <li>Twenty one</li>
 <li>Twenty two</li>
 <li>Twenty three</li>
 <li>Twenty four</li>
 <li>Twenty five</li>
<div id="loadMore">Load more +</div>
<div id="showLess">Show less -</div>

Below images show example how you can do this and how it will be displayed.

Load more content
Step 1
Step 2
Step 3

Add a Script to footer of your website

Use below script add this into footer of website and make sure it will not conflict with any code.

$(document).ready(function () {
 size_li = $("#myList li").size();
 $('#myList li:lt('+x+')').show();
 $('#loadMore').click(function () {
 x= (x+5 <= size_li) ? x+5 : size_li;
 $('#myList li:lt('+x+')').show();
 $('#showLess').click(function () {
 x=(x-5<0) ? 3 : x-5;
 $('#myList li').not(':lt('+x+')').hide();

Add CSS to for styling as you need

#myList li{ display:none;
#loadMore {
 padding: 5px 11px;
 cursor: pointer;
 background: #e8e8e8;
 width: 75px;
 margin: 3px;
 position: relative;
 border-radius: 7px;
#showLess {
 padding: 5px 11px;
 cursor: pointer;
 background: #e8e8e8;
 position: relative;
 border-radius: 7px;
 width: 75px;
 margin: 3px;

Above code tasted by me many times hope these work for you as well let me know if any question or suggestion in comment section below. Don’t forget to subscribe via email.


Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *