When you click on the button it will seem that nothing happened. It makes it possible for a function to have " private " variables. Don't use the word "click" as the function name. ADVERTISEMENT Well be incrementing the value of c by 1, and updating the count element. How to create a text that permit to send email in HTML document when button is clicked ? Can a VGA monitor be connected to parallel port? The MouseEvent object passed into the event handler for click has its detail property set to the number of times the target was clicked. Lets assign this interval to a variable interval, so we can clear this interval when the times up. And the name of the function and that typo in. Lets start with and event listener for the increment button. You can achieve the same result by using counter = counter + 1 For our minus eventlistener we can use counter-- which is the same as counter++ but with subtracting instead of adding. In this tutorial, lets look at how to create a counter in JavaScript. By having our new function we can call it at the start of the document. Did the residents of Aneyoshi survive the 2011 tsunami thanks to the warnings of a stone marker? Example: This example shows the number of times a button is clicked. Starting with some simple HTML, an h1 for the display of the current count and Buttons for adding and subtracting. Like, what if I have the text "blabla . In case of any confusion feel free to write me a comment and I'll try to update my post to be more clear! First text and second id button, on clicking a button text input will increase current value by one. The Y coordinate of the mouse pointer in local (DOM content) coordinates. If stewyearth is not suspended, they can still re-publish their posts from their dashboard. This lets you, for example, determine whether a mouse event was generated by an actual mouse or by a touch event (which might affect the degree of accuracy with which you interpret the coordinates associated with the event). Its going to get updated with the new value for every count. This example displays the number of consecutive clicks on a