0
I need some help with counting clicks
I have no coded anything but I want to have 2 buttons, everytime the user click on this buttons should increase clickcounter for 1.
6 Réponses
+ 4
Sure👍
+ 3
given a global variable "clickcounter" you can put this html template for your buttons:
<button onclick="clickcounter++">ButtonText</button>
+ 3
Isaac Chavez,
In additional to KrOW's correct answer,👍
Here is a snippet:
var clickcounter = 0;
function count1(){
clickcounter += 1;
var doc = document.getElementById("counter");
doc.innerHTML = clickcounter;
}
function count2() {
clickcounter -= 1;
var doc = document.getElementById("counter");
doc.innerHTML = clickcounter;
}
Preview snippet:
https://code.sololearn.com/WLA937y8v2D4/?ref=app
+ 3
onclick attribute will even work on the body tag 😋
0
Can I do the same for a div with an id? Instead of a button?
0
Isaac Chavez But make sure the width/height of the div are what you want.