Your are binding $("#innerClicker")
the event every clicked element
$(document).ready(function () {
var kisses = 0;
$("#main").delegate(".kisser", "click", function () {
$("#inner").css("display", "block");
$("#hint").css("display", "none");
foo();
});
function foo() {
kisses++;
}
$("#innerClicker").click(function () {
if (kisses) {
$(".results").html("Kissed <h1>" + kisses + "</h1> times. <br />");
$("#inner").css("display", "none");
$("#hint").css("display", "block");
}
});
});
UPDATED DEMO
NOTE : IF you bind the element every clicked .it will be added and fired how many times you were clicked ,and also use on
method instead of delegate
,the delegate method was deprecated in new version of jquery
solved jQuery Functional Looping : Why does Shakira repeats the kisses as new person kissed her? [closed]