To with this 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 that with each click, only 3 numbers appear. Example: I clicked aparecer
, then it appears: 1,2,3 clicked again, 4,5,6 clicked again, 7,8,9 and then click again to appear only 10.
Always creating a new UL, not replacing the current one.
How do I do this?