JavaScript で table の行(tr)を入れ替えようと次のように書いたら Node not found っていうエラーが出た。
function swap(a, b) { var table = document.getElementById('table_name'); var clone = table.rows[a].cloneNode(true); table.replaceChild(table.rows[b], table.rows[a]); table.replaceChild(clone, table.rows[b]); }
これは rows が table のプロパティに過ぎず、Node ではないから(だと思ってる。)replaceChild は、子ノードを要求する。次のようにしたら問題なくなった。
続きを読む