Pre-attach events
Using .on with event delegation see http://stackoverflow.com/a/20977690
by Bruno G.
HTML
<div class="test"><button class="ok">Check event</button></div>
<button onclick="goTest();">Add button</button><br>
<div id="test" class="test"></div>
JavaScript
goTest = function() {
$('#test').html('<button class="ok">New Button!</button>');
}
$('.test').on('click', '.ok', function(){Yes();});
function Yes() {
alert('YES!');
}