Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
})
 
PREVIOUS NEXT
Tagged: #CREATE #A #BUTTON #THAT #INCREMENTS #A #COUNTER #WHEN #CLICKED
ADD COMMENT
Topic
Name
3+4 =