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 :: js click counter 
Javascript :: javascript object array contains 
Javascript :: avascript regex email 
Javascript :: fetch Response object get content type 
Javascript :: jquery document ready function 
Javascript :: preview upload image jquery 
Javascript :: javascript count no of lines 
Javascript :: Easy REACT download image 
Javascript :: javascript is array empty 
Javascript :: how to enable click copy function using js 
Javascript :: how to get common elements from two array in javascript using lodash 
Javascript :: javascript get sub array 
Javascript :: js check if array of dictionaries contain 
Javascript :: quasar change port 
Javascript :: domparser is not defined 
Javascript :: get the state of a checkbox 
Javascript :: how to pip install jsonlines 
Javascript :: generate express js project 
Javascript :: js array last element get 
Javascript :: javascript new date from string dd/mm/yyyy 
Javascript :: sort js 
Javascript :: how to convert json to javascript object in ajax success 
Javascript :: string to date js 
Javascript :: javascript create array with repeated values 
Javascript :: how to insert an item into an array at a specific index javascript 
Javascript :: npm i postman 
Javascript :: use style in react 
Javascript :: window.print filename 
Javascript :: begins_with node js AWS dynamodb sort key 
Javascript :: deduplicate array javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =