This script is designed to display only three items at a time and reveal the next set of three items when the Next Button is clicked.
let currentPage = 0;
const pages = 5;
const itemsPerPage = 3;
const $submitButton = $("button[type=submit]");
$("li h3").each(function(index, element){
$(element).text((index + 1) + ") " + $(element).text());
});
$("#next").click(function() {
$("li")
//.css("background", "#FFF")
.hide();
for(let i = 1; i <= itemsPerPage; i++) {
$("li:nth-child(" + ((currentPage * itemsPerPage) + i) + ")")
//.css("background" , "red")
.show();
}
if(currentPage === pages - 1) {
$submitButton.show();
} else {
$submitButton.hide();
}
if(currentPage < pages - 1) {
currentPage += 1;
} else {
currentPage = 0;
}
});
$("#next").click();
Check out the live example on CodePen