Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

CREATE A BUTTON THAT INCREMENTS A COUNTER WHEN CLICKED

## 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 :: increased the value of a counter when a button is clicked in js 
Javascript :: counter in javascript 
Javascript :: foreach break js 
Javascript :: how to install vue 
Javascript :: js looping through array 
Javascript :: upload preview image jquery 
Javascript :: javascript convert array to object 
Javascript :: font awesome cdn svg with js 
Javascript :: react bootstrap form select 
Javascript :: setting timeout in javascript 
Javascript :: js html tag valu 
Javascript :: how to disable a button in react based on condition 
Javascript :: express router file 
Javascript :: jquery get duration video tag 
Javascript :: input on change angular 2 
Javascript :: if between two numbers javascript 
Javascript :: node express app.listen at specific port & host 
Javascript :: javascript element onblur 
Javascript :: string literal javascript 
Javascript :: how to get the size of the window in javascript 
Javascript :: js hexadecimal 
Javascript :: vscode rest api extention POST method 
Javascript :: vue scroll div to bottom 
Javascript :: oneerror javascript image 
Javascript :: how to use console.log in vuejs 
Javascript :: mapgetters with parameter 
Javascript :: sort in javascript array 
Javascript :: No provider for ReducerManager 
Javascript :: encrypt decrypt in vanilla javascript 
Javascript :: puppeteer headless 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =