SI Works blog
AUG
12
I came across this really nifty little script on Elliot Swan's website while looking for something to help me with a task I have, the task is to copy an element and everything inside the element. this works great, I've made my own small tweaks in order to make sure it 100% suits the application I'm using it for, other than that, nice one.
var Move = {
copy : function(e, target) {
var eId = $(e);
var copyE = eId.cloneNode(true);
var cLength = copyE.childNodes.length -1;
copyE.id = e+'-copy';
for(var i = 0; cLength >= i; i++) {
if(copyE.childNodes[i].id) {
var cNode = copyE.childNodes[i];
var firstId = cNode.id;
cNode.id = firstId+'-copy'; }
}
$(target).appendChild(copyE);
},
element: function(e, target, type) {
var eId = $(e);
if(type == 'move') {
$(target).appendChild(eId);
}
else if(type == 'copy') {
this.copy(e, target);
}
}
}
Take a look at the entry for this and find more instructions.




Current Comments
There are currently no comments Why don't you be the first?