I have added a button dynamically. But when I click it, it fires multiple click events and calls the associated function with alert('clicked'); several times and not just one time.
Can you tell me why and how I can fix it?
Code
var root = document.getElementById('current_page');
var button = document.createElement('input');
button.type = 'button';
button.title = 'Add new book to list';
button.className = 'btn btn-primary';
button.id = 'get_new';
button.setAttribute('value', 'No Thanks,Get New');
button.setAttribute('style', 'position:relative; top:-5px;left:900px');
root.appendChild(button);
Handler
$('body').on('click', '#get_new', function () {
alert('clicked');
});
alert('clicked');is fired more than once on a single click.