-1

I'm having a problem, how to get a number of clicks on a button in jQuery?

I am familiar with javascript code, so any help would be useful.

2 Answers2

-1

You have to create a variable outside of the function scope so it doesn't get reset each time the function is called.

var counter = 0;

function add()
{
  counter++;
  console.log("Button has been clicked", counter, "times(s)");
}
<button onclick="add()">Click me!</button>
silentw
  • 4,835
  • 4
  • 25
  • 45
-1
let clicks = 0;
button.addEventListener('click', () => clicks++);
Scrapper142
  • 566
  • 1
  • 3
  • 12