I faced this problem while doing some exercises. Can't select recently added button number two, and cant call alert method
$('#but').click(function() {
$('#but').after('<button id="but2">Кнопка 2</button');
});
$('#but2').click(function() {
alert('something');
});
Having only this HTML code:
<button id="but">Кнопка 1</button>