0
I have that code here:
function aparecer(){
const array1 = [1,2,3,4,5,6,8,9,10];
for (let i=0; i < array1.length;i++){
const lugar = document.getElementById('local');
const ul = document.createElement('UL');
const valor = document.createTextNode(array1[i])
ul.appendChild(valor);
lugar.appendChild(ul)
break
}
}
function desaparecer(){
document.getElementById('local').innerHTML= '';
}
<html>
<button onClick='aparecer()'> Aparecer </button>
<button onClick='desaparecer()'> Desaparecer </button>
<div id='local'> </div>
</html>
And I want every click to appear only 3 numbers. Example: I clicked on aparecer
, ai appears: 1,2,3 clicked again, appears 4,5,6 clicked again, 7,8,9 and just after clicking again appear only the 10.
Always creating a new UL, and not replacing the current.
How do I do that ?
Perfect, about the parade, tried to use
break;
to stop andcontinue;
to shoot from where you left off?– RpgBoss
@Marcelorafael Otimo Marcelo, thank you very much, but a doubt, if I want to change the numbers by changing them? Example: Click and appear: 1,2,3 Click again and appear: 4,5,6 instead of 1,2,3, in this case, replacing 1,2,3 by 4,5,6
– Jota
Just go ahead and clean the container with
element.innerHTML = ''
– Alex