[jQuery] Cloning Fieldsets

[jQuery] Cloning Fieldsets


Err hello?
Managed to get it working ... kind of.... but out of interest wanted
to know if I was missing some jQuery idioms within the .each()
function?
Any thoughts gratefully received.
R. ( Noobie )
function addSubform(childtype) {
subformCount++;
var thisType = childtype;
var mysubform = $('#'+childtype
+'_tmpl').clone().appendTo('#'+childtype+'_insert');
mysubform.attr('id',childtype+'_'+subformCount).show();
var i_tag = '#'+childtype+'_'+subformCount+' > ol > ';
var p_tag = i_tag+' li > ';
$( i_tag+'input, '+p_tag+'input, '+p_tag+'label, '+p_tag
+'textarea').each(function(index) {
/* old_school starts here ...*/
var prefix = thisType;
if (this.tagName == 'INPUT' || this.tagName == 'TEXTAREA' ) {
var theName = this.name; // strip off tmpl_
theName = theName.replace("tmpl_","");
if (theName) this.name = prefix+'[' + subformCount + '][' +
theName + ']' ;
var theID = this.id
theID = theID.replace("tmpl_","");
if (theID)
this.id = prefix+'_' + subformCount + '_' + theID ;
}
if (this.tagName == 'LABEL') {
var theName = this.getAttribute('for'); // strip off tmpl_
theName = theName.replace("tmpl_","");
if (theName) this.htmlFor = prefix+'_' + subformCount + '_' +
theName;
}
/* .. and has ended by here */
});;
return false;
}