I am trying to build a reset function for a timer. I do understand how to reset the value of one button, but I cannot figure out how I can assign the same function to different buttons with each their own timer.
Currently I use the code below, but it specifically targets one element, while it should work on different ones.
<html>
<head>
<script>
function resettimer() {
var x = document.getElementsByClassName("timer");
x[0].innerHTML = "Hello World!";
}
</script>
</head>
<body>
<table>
<tr>
<p class="timer">Timer 1</p>
<button onclick="resettimer()">Reset timer 1</button>
</tr>
<tr>
<p class="timer">Timer 2</p>
<button onclick="resettimer()">Reset timer 2</button>
</tr>
<tr>
<p class="timer">Timer 3</p>
<button onclick="resettimer()">Reset timer 3</button>
</tr>
<tr>
<p class="timer">Timer 4</p>
<button onclick="resettimer()">Reset timer 4</button>
</tr>
<table>
</body>
</html>