Good day,
I have written a simple jQuery statement which should create some HTML buttons dynamically and link them to a click event handler. Unfortunately, every time I click on a certain created button, the even runs not once, but as many times as buttons were ever created. Any help on this issue would be very appreciated! Thank you!
My code is:
$(document).ready(function () {
var i = 0;
$('#start_button').click(function () {
$("#game_board").append($("<input type='button' class='click-point' id='" + (i++) + "' value='test" + i + "' />"));
$("#game_board").on("click", ".click-point", function (event) {
$(this).remove();
$('#current_score').text(parseInt($('#current_score').html(), 10) + 1);
});
});
});