Javascript – How to move an element around DOM tree without affecting related javascript

domjavascriptmootools

In this case I have a containing an iFrame that has an editor, mooEditable. I clone the element with IDs, destroy old one and insert new one where needed.

Javascript component doesn't work anymore at this stage. If there is a generic way to do this, it would be terrific if you share it.

TIA

Best Answer

Perhaps you could show the gist of what you do? Specifically, what do you mean by "destroy old one"?

This uses jQuery, but you could code to the bare metal if you want:

var item = $('#item-id');  // item to move
var want = $('#new-div');  // container to receive it
item.remove();
want.append(item);

You may have trouble moving iframes (not sure). If so, and if you're just swapping two items, move the other one.