Hi I am trying to insert a JQuery object inside another by doing the following:
var htmlCode = $("<div id='"+data.layoutDescriptions[i].id+"'></div");
if(data.contentRef == "RecursiveContactSubForm"){
if(htmlArray[2]){
alert("in here");
htmlCode.append(htmlArray[2]);
}
else{
alert("in here2");
var tmp = htmlCode;
htmlCode.append(tmp);
}
}
I don’t understand why this doesn’t work.
any ideas?
Thanks.
I’m assuming your error is here:
This assignment will not create a copy of
htmlCode, it will create a new reference to it.tmpandhtmlCoderepresent the same object, so attempting to append an object to itself will fail.You can use the
clonefunction:Passing
truetoclonewill copy any events and data attached to the object into the new object as well.