Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

increased the value of a counter when a button is clicked 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
})
 
PREVIOUS NEXT
Tagged: #increased #counter #button #clicked #javascript
ADD COMMENT
Topic
Name
1+3 =