Hide “Load More” Button When All Items Displayed ?

Last updated on April 29th, 2020 at 03:40 am

If You Want To Hide ‘load more’ Button When All Items Displayed Even Items Are 7 or 10 or 25…Just Hide ‘load more ‘ Button When All Items Loaded.

Both .size() and .length identify the number of items:

Note: This method has been removed in jQuery 3.0. Use the .length property instead.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>

$(document).ready(function () {
     list_size = $("#List li").length; 
       x=4; 
            $('#List li:lt('+x+')').show(); 
	
            $('#loadMore').click(function () {  
               x= (x+3 <= list_size) ? x+3 : list_size;
               $('#List li:lt('+x+')').show(); 
               //hide loadmore when all items displayed  
               $(this).toggle(x < list_size);  
                                             }); 
							 }); 
   
</script>
<style>
	#List li{ display:none;
	}
	#loadMore {
		color:green;
		cursor:pointer;
	}
	#loadMore:hover {
		color:black;
	}
</style>

<body>
<ul id="List">
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
    <li>Five</li>  
	<li>six</li> 
    <li>seven</li>

</ul>
<div id="loadMore">Load more</div>
</body>

  • One
  • Two
  • Three
  • Four
  • Five
  • six
  • seven
Load more
Share Post

19 thoughts on “Hide “Load More” Button When All Items Displayed ?”

  1. Предлагаем услуги профессиональных инженеров офицальной мастерской.
    Еслли вы искали ремонт ноутбуков lenovo сервис, можете посмотреть на сайте: ремонт ноутбуков lenovo
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  2. After research a couple of of the blog posts on your web site now, and I truly like your method of blogging. I bookmarked it to my bookmark web site checklist and might be checking again soon. Pls take a look at my site as effectively and let me know what you think.

  3. Thanks for the advice on credit repair on this particular blog. The things i would offer as advice to people will be to give up this mentality that they may buy today and pay back later. As being a society most people tend to do this for many issues. This includes vacations, furniture, as well as items we really want to have. However, it is advisable to separate the wants out of the needs. While you’re working to improve your credit score actually you need some trade-offs. For example you are able to shop online to save money or you can check out second hand shops instead of costly department stores pertaining to clothing.

  4. The heart of your writing while sounding reasonable at first, did not work well with me after some time. Somewhere within the paragraphs you actually managed to make me a believer unfortunately only for a short while. I nevertheless have a problem with your jumps in logic and you would do nicely to help fill in all those breaks. When you can accomplish that, I could surely end up being amazed.

Leave a comment