I'm available on Fiverr.com. Hire me today!
Load More Button With CSS and jQuery
Q&A

Load More Button With CSS and jQuery

06 Aug, 2023

It's common practice to add a "Load More" button to a web page using jQuery and CSS to display more content without refreshing the entire page. Here is a detailed explanation on how to do it:

1.HTML Structure:

First, create your HTML structure with a container to hold the content and a "Load More" button.

<div class="container text-center">
	<div class="row">
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
		<div class="col-md-4">
			<div class="content"></div>
		</div>
	</div>
	<a href="" class="load-more">Load More</a>
</div>
2.CSS Styling (styles.css):

Add some basic CSS styles to control the layout and appearance of the container and the "Load More" button.

.container{
  margin:30px auto;
}

.col-md-4{
  display:none;
}

.content{
  background-color:#333;
  height:200px;
  margin:10px 0;
  border:1px solid #ccc;
}

.load-more{
  background-color:#000;
  color:#fff !important;
  padding:5px 10px;
  border-radius:4px;
  font-size:20px;
  margin:50px 0;
  display:inline-block;
}

.load-more:hover{
  background-color:blue;
  text-decoration:none;
}
3.JavaScript (script.js):

Include jQuery in your project and use it to handle the "Load More" button functionality.

$(function () {
		$(".col-md-4").slice(0, 3).show();
		$("body").on('click touchstart', '.load-more', function (e) {
			e.preventDefault();
			$(".col-md-4:hidden").slice(0, 3).slideDown();
			if ($(".col-md-4:hidden").length == 0) {
				$(".load-more").css('visibility', 'hidden');
			}
			$('html,body').animate({
				scrollTop: $(this).offset().top
			}, 1000);
		});
	});
When the "Load More" button is clicked, the next set of concealed content items are revealed. The aforementioned JavaScript code initially conceals the extra content. The button is hidden to signal that all material has been shown when there are no longer any hidden items.

I'm done now! The aforementioned HTML, CSS, and JavaScript code allows you to create a "Load More" button that works with CSS and jQuery. To suit your particular use case, alter the increment value and the number of beginning elements.

Share With  Facebook  Twitter  Pinterest  Linkedin  WhatsApp

 Top 5 Related Query

Leave a Reply