innerHTML non è appropriata in questo contesto:
codice:
<!doctype html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<input type="button" class="btn" value="bottone1"><br>
<input type="button" class="btn" value="bottone2"><br>
<input type="button" class="btn" value="bottone3"><br>
<input type="button" class="btn" value="bottone4"><br>
<script>
const buttons = document.getElementsByClassName("btn");
const handler = e => { console.log("Clic su " + e.target.value) };
// "for ... of" method
// for (button of buttons) {
// button.addEventListener("click", handler);
// }
// "forEach" method
Array.from(buttons).forEach(e => {
e.addEventListener("click", handler);
})
</script>
</body>
</html>