I have this code:
let inicial = -0;
const numeros = [1,2,3,4,5,6,7,8,9,10];
function proximo (){
inicial++
document.getElementById("lugar").innerHTML=''
alert(inicial)
for(let i = inicial-1; i < inicial+2; i++){
const ul = document.createElement('UL');
const numerosUl = document.createTextNode(numeros[i]);
const lugarElement = document.getElementById("lugar");
ul.appendChild(numerosUl);
lugarElement.appendChild(ul);
}
}
function limpar(){
document.getElementById("lugar").innerHTML=''
}
<html>
<button onClick="proximo()"> Próximo </button>
<div id="lugar"> Teste </div>
<button onClick="limpar()"> Limpar </html>
</html>
It's showing up in 3 in 3 numbers, however, I want it to update itself every time it clicks on the array itself.
Example: If you click now, 1,2,3 will appear. I want it when I click next time, it appears: 4,5,6 and in the next: 7,8,9 and in the last click, it appears: 10. Not creating new elements in the body but updating it.
Could someone help me and if possible explain what was done? I just want this change, to start from the number that does not appear on the screen, that is from the beginning, 1 to 3, and start from 4 and go to 6 and start from 7 and go to 9 and when you last click 10.