Gm5,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<p class="elem">lorem</p>
<p class="elem">lorem</p>
<p class="elem">lorem</p>
<p class="elem">lorem</p>
<p class="elem">lorem</p>
<p class="elem">lorem</p>
<p class="elem">lorem</p><button id="button">go</button>
<script>
let elems = document.querySelectorAll('.elem');
let button = document.querySelector('#button');
button.addEventListener('click', function(){
for(let i=0;i<elems.length; ){
let elem= elems[i++];
elem.innerHTML += i;
}
});
</script>
</body>
</html>