The clone() function returns the cloned object instead of a copy. Thus, when I modify what it should be the copy, it modifies the original too. This only occurs when I assign the object to clone to a variable and use this variable to call the clone function. For example:
// works as expected
var templateDivCopy = $('#templateDiv').clone().get(0);
templateDivCopy.innerHTML = 'This should be only in the copy';
if(templateDiv.get(0).innerHTML === 'This should be only in the copy') { // they're different
alert('The original was affected too!')
}
templateDivCopy.innerHTML = 'This should be only in the copy';
if(templateDiv.get(0).innerHTML === 'This should be only in the copy') { // they're different
alert('The original was affected too!')
}
// does not work as expected
var templateDiv = $('#templateDiv');
var templateDivCopy = templateDiv.clone().get(0);
templateDivCopy.innerHTML = 'This should be only in the copy'; //modifies the original too
if( templateDiv.get(0).innerHTML === 'This should be only in the copy') { // they are equal
alert('The original was affected too!')
}
var templateDivCopy = templateDiv.clone().get(0);
templateDivCopy.innerHTML = 'This should be only in the copy'; //modifies the original too
if( templateDiv.get(0).innerHTML === 'This should be only in the copy') { // they are equal
alert('The original was affected too!')
}
I think this is a bug.
Is there a fix yet?
Thanks
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
