In your original code, you are binding the click event to a non-existant object (non-existant at the time of binding).
The following binds the click event after inserting the textarea into the DOM and should work.
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy">'+$(this).text()+'</textarea>');
// at this point, the textarea exists and the binding will work.
$('#copy').click(function() {
$(this).select();
});
});
Another way is bind using on() for any click on #copy on the document object.
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy">'+$(this).text()+'</textarea>');
});
// in this case, it will work even if #copy is non-existant at the time of binding
$(document).on('click', '#copy', function() {
$(this).select();
});