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.

22nd Sep 2018, 6:51 PM
Isaac
Isaac - avatar
6 Respuestas
+ 4
Sure👍
22nd Sep 2018, 7:37 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 3
given a global variable "clickcounter" you can put this html template for your buttons: <button onclick="clickcounter++">ButtonText</button>
22nd Sep 2018, 7:04 PM
KrOW
KrOW - avatar
+ 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
22nd Sep 2018, 7:14 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 3
onclick attribute will even work on the body tag 😋
22nd Sep 2018, 7:37 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
Can I do the same for a div with an id? Instead of a button?
22nd Sep 2018, 7:32 PM
Isaac
Isaac - avatar
0
Isaac Chavez But make sure the width/height of the div are what you want.
22nd Sep 2018, 8:09 PM
Bebida Roja
Bebida Roja - avatar