How to count the number of times a button is clicked using JavaScript ? (original) (raw)

Last Updated : 15 Dec, 2023

At times, it becomes necessary to monitor the number of times a user clicks a button. In this article, we are going to learn how to count the number of times a button is clicked using JavaScript

Below are the approaches to count the number of times a button is clicked using JavaScript

Table of Content

**Using the **onClick()

First, we will create an HTML button and a paragraph element where we display the button click count. When the button is clicked, the JavaScript function is called. We declare a count variable and initialize it to 0. When the user clicks the button, the count value increases by 1 and displays on the screen.

**Example: This example shows the number of times a button is clicked.

HTML `

GeeksforGeeks

How to count the number of times a button is clicked?

Click Here!

Button Clicked 0 Times