テーブルを取得して列の順序を変更できる jquery プラグインを作成しています。
oldIndex の位置にある列を newIndex の位置に配置するコードは次のとおりです。
table.find('> thead > tr, > tbody > tr').each(function() {
var row = $(this);
var children = row.children();
var source = $(children[oldIndex ]);
var destination = $(children[newIndex ]);
if (oldIndex != newIndex ) {
destination
.replaceWith(source)
.appendTo(row);
}
});
問題は、各 td にこのコードの外にあるイベントがあることです。を使用するreplaceWith
と、それらのイベントが削除されます。
DOM 要素の位置を置き換えて、そのイベントを保持できるアイデアはありますか?