5

コンテンツをクローンせずにjQueryでDOM要素のクローン/コピーを作成することは可能ですか? div のコンテンツを、同じ属性を持つ 2 つの別個の div に分割する必要があります。たとえば、次のように変更する必要があります。

<div class="someclass" someattr="someval">
    this is the first sentence. this is the second sentence.
</div>

次のようなものに:

<div class="someclass" someattr="someval">
    this is the first sentence.
</div>
<div class="someclass" someattr="someval">
    this is the second sentence.
</div>

コンテンツをどのように分割するかはかなり複雑ですが、基本的にはこれが私がする必要があることです。明らかに、コンテンツなしでクローンを作成するには、次を使用して実現できます。

$(el).clone().empty();

しかし、要素がかなり大きくなる可能性があるため、要素のコンテンツを不必要に複製するオーバーヘッドを取り除きたいと考えています。アイデア?ありがとう!

4

1 に答える 1