Mam trzy guziki na stronie i jeden licznik. Chce napisać skrypt który umożliwi mi że naciśnięcie tych trzech guzików będzie zwiększać licznik
Tu jest mój kod js
let buttons = document.querySelectorAll("button");
Array.from(buttons).forEach(function(button) {
button.addEventListener("click", function() {
button.nextElementSibling.firstElementChild.innerHTML = parseInt(button.nextElementSibling.firstElementChild.innerHTML) + 1;
})
})
tutaj jest kod html
<button id="button1">Guzik 1</button>
<button id="button2">Guzik 2</button>
<button id="button3">Guzik 3</button>
<p>
Wartość licznika: <span class="counter">0</span>
</p>