Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to increment counter button click in javascript

## MY HTML
<button id='counter'>Click Me To Count</button>
<span id='result'>1</span>

## MY JAVASCRIPT
let counter = document.getElementById("counter")
let result = document.getElementById("result")
let count = 1

counter.addEventListener("click", () => {
  count += 1
  result.innerHTML = count
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript click counter 
Javascript :: check if isset variable js 
Javascript :: how to break the foreach loop in javascript 
Javascript :: install vue js 
Javascript :: check for duplicates in array javascript 
Javascript :: preview upload image js 
Javascript :: javascript object to array 
Javascript :: js count element tags 
Javascript :: js how to check is array empty es6 
Javascript :: copy link to clipboard 
Javascript :: what is the use of bind method in javascript 
Javascript :: javascript sort array of object by property 
Javascript :: reactsj substring 
Javascript :: next js image 
Javascript :: setting up fontawesome with react project 
Javascript :: axios delete request payload 
Javascript :: get file extension nodejs 
Javascript :: select react hook form yup validation 
Javascript :: javascript two decimal places after division 
Javascript :: how to filter list of objects by an array in javascript 
Javascript :: sequelize change column 
Javascript :: delete all objects in array of objects with specific attribute 
Javascript :: how the filter() function works javascript 
Javascript :: Use Multiple Conditional Ternary Operators Javascript 
Javascript :: jquery post 
Javascript :: remove part of string javascript 
Javascript :: sorting in javascript 
Javascript :: how to unselect input javascript 
Javascript :: what is functional composition 
Javascript :: fs.readfile 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =