I had a need to alter a bunch of ids and names after I cloned a dom node, so I cooked up the following dom node visitor:
function domVisitor(el, f) {
if (el) {
f(el);
for (var i=0 ; i < el.childNodes.length ; i++) {
domVisitor(el.childNodes[i], f);
}
}
}
So all you need to do is pass in the cloned node (or whatever) along with an anonymous function to do your bidding. The function will be called for the full tree under the node passed in.