Have you tried to do
$div = $('<div>', { id : "confirmation"}); $aConfirmed = $('<a>', { href : "#", class : "confirmed", text: "confirmed"}); $aCancel = $('<a>', { href : "#", class : "cancel", text: "Cancel"}); $div.append($aConfirmed).append($aCancel); $('body').append($div);
And then use some event handlers like (this assumes jQuery> 1.7
$(document).on("click", "a.confirmed", function(){ confirmed(); }); $(document).on("click", "a.cancel", function(){ closeConfirm(); });
source share