This is what I've tried:
html:
<div id="container">
<p>a paragraph</p>
</div>
<button>replace with link</button>
script:
$(document).ready(function() {
$("a.foo").click(function() {
alert('hello world');
});
function foo() {
alert('hello world');
}
$("button").click(function () {
// neither of these work
// $("#container p").replaceWith('<p><a href="#" class="foo" >trigger function<\/a><\/p>');
// $("#container p").replaceWith('<p><a href="#" onclick="foo();return false" >trigger function<\/a><\/p>');
});
});