0

var destinationその前に複数の要素を挿入しようとしている要素があります。使っ.beforeていますが、複数の要素を動かしているので何度も使っています。

このコードを改善し、すべての要素を一度に移動する方法はありますか?要素、その前の要素、およびを使用moveElementするクラスを持つ他の多くの要素を移動しています。の数を減らすための任意の方法myClasseach()destination.before()

destination.before(moveElement.prev());
destination.before(moveElement);
$('div.myClass').each(function(){
   destination.before($(this));
});
4

1 に答える 1

3

beforejqueryオブジェクトを受け入れるため、すべての要素を使用してjQueryオブジェクトを作成できます。

destination.before(moveElement.prev().add(moveElement).add('div.myClass'));

addドキュメント:

説明:一致した要素のセットに要素を追加します。

于 2012-06-03T20:46:31.803 に答える