There are several ways you can get what you want, one of them is this:
First we will set the value that will start to display (for easier execution, put 5 instead of 10). This value is in var count = 5;
.
To start, we will use the .Slice() to select the elements we wish to hide.
After that, we will use the event .click() to load more elements. To illustrate, I just add the variable value count
with 5 count += 5;
. and make a loop of all items smaller than this value, showing the same with the .show().
I think you’ll understand better in the example below:
(function($) {
//Setamos o valor inicial
var count = 5;
//escondemos todos os elementos maior que o valor inicial
$("li").slice(count).hide();
$('#carrega-mais').click(function() {
//Somamos a quantidade nova a ser exibida
count += 5;
//Rodamos o loop no valor total
for (var i = 0; i < count; i++) {
//Mostramos o item
$('li').eq(i).show();
}
});
}(jQuery));
button {
margin-bottom: 60px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>TESTE 1</li>
<li>TESTE 2</li>
<li>TESTE 3</li>
<li>TESTE 4</li>
<li>TESTE 5</li>
<li>TESTE 6</li>
<li>TESTE 7</li>
<li>TESTE 8</li>
<li>TESTE 9</li>
<li>TESTE 10</li>
<li>TESTE 11</li>
<button id="carrega-mais">Carregar mais 5</button>
The ideal would be to count the amount of li
to hide the button carry more when it no longer has elements, but this I leave to you to complement. xD
hide how many at a time?
– user60252
It will display from 10 to 10... whenever you click the button press 10 more...
– Cleberson Gomes