0

How to count click events in JavaScript

var count = 0;
var countButton = document.getElementById("countButton");
var displayCount = document.getElementById("displayCount");
countButton.onclick = function(){
  count++;
  displayCount.innerHTML = count;
}
resetButton.onclick = function(){
  count = 0;
  displayCount.innerHTML = count;
}
<div>
<input type="button" value="CLICK HERE" id="countButton" />
Button was pressed - <span id="displayCount">0</span> - times. 
<input type="button" value="RESET" id="resetButton" />
</div>
#countButton{
  padding: 5px 5px;
}
#resetButton{
  padding: 5px 5px;
}
RUN
add comment
Suggest a different solution or add another example