に割り当てることは可能select()
ですreplaceWith()
か?
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy">'+$(this).text()+'</textarea>');
});
$('#copy').click(function() {
$(this).select();
});
私は上記のコードを試しましたが、うまくいきません(これはreplaceWith()
架空の要素であるためだと思います(私が言っていることを理解した場合))。
しかし、私はそれを中に置くことによってそれを機能させonclick="this.focus();this.select()"
ましたreplaceWith()
$('#foo').one('click', function() {
$(this).replaceWith('<textarea id="copy" onclick="this.focus();this.select()">'+$(this).text()+'</textarea>');
});
replaceWith()
しかし、最初のコードがやろうとしているように、コードの外でそれを好むでしょう。