Raziel Alvarez schrieb:
> 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:
>
> *// 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!')
> }
>
>
> I think this is a bug.
By calling clone(), the jQuery object saved as templateDiv is modified.
This seems to solve the problem:
var templateDivCopy = $(templateDiv).clone().get(0);
Wrapping the variable templateDiv into the jQuery constructor clones the
jQuery object itself, therefor it can be modified without affecting
templateDiv itself.
-- Jörn
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/