To count button clicks in Javascript you can use the following snippet.

Sample Javascript

$('myButton')
    .data('counter', 0)
    .click(function() {
        var counter = $(this).data('counter');
        $(this).data('counter', counter + 1);
        alert($(this).data('counter'));
    });

2 thought on “How to count button clicks in Javascript”

Leave a Reply