Is it possible to assign select()
to a replaceWith()
?
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy">'+$(this).text()+'</textarea>');
});
$('#copy').click(function() {
$(this).select();
});
I've tried the above code but it dosen't work (I assume this is because the replaceWith()
is a fictional element (if you get what I mean)).
I have however got it working by placing onclick="this.focus();this.select()"
inside the replaceWith()
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy" onclick="this.focus();this.select()">'+$(this).text()+'</textarea>');
});
but would prefer it outside of the replaceWith()
code like the first code is trying to do.