You need to use named functions.
In addition, the click variable must be outside the handler to increase.
var click_count = 0; function myClick(event) { click_count++; if(click_count == 50) {
EDIT:. You can close the click_counter variable as follows:
var myClick = (function( click_count ) { var handler = function(event) { click_count++; if(click_count == 50) {
Thus, you can increase the counter by several elements.
If you do not want this and want everyone to have their own counter, do the following:
var myClick = function( click_count ) { var handler = function(event) { click_count++; if(click_count == 50) {
EDIT: I forgot to call the handler returned in the last two versions. Fixed.
user113716 Dec 09 '10 at 19:41 2010-12-09 19:41
source share