I want to create a simple paging based on elements within an array.
When I get to the first and / or last element of the array, I would like to disable its navigation button (eg, changing from disabled=false
to disabled=true
)
Code
<button onclick="Anterior();" id="menos">Anterior</button>
<span id='numero'> </span>
<button onclick="Proximo();" id="mais">Próximo</button>
<script>
var elemento = new Array(1, 2, 3, 2, 7);
contar = 0
Proximo = function() {
contar ++;
...
};
Anterior = function() {
contar --;
...
};
// retorna o primeiro indice do array
var menor = document.write(elemento.indexOf(searchElement[, fromIndex]))
// retorna o último índice do array
var maior = document.write(elemento.slice(-1)[0])
if (contar == menor) {
document.getElementById('menos').disabled=true;
}
if (contar == maior) {
document.getElementById('mais').disabled=true;
}
</script>
Then it would look aesthetically like this:
[Previous] - 3 - [Next]
I would like it to count inside the element span