Ok, I won't argue anymore about the clone(), though I think it's not the behaviour that anyone expects (think on the cloneNode() function) and the documentation then is incorrect or very very confusing: "Create cloned copies of all matched DOM Elements. This does not create a cloned copy of this particular jQuery object, instead it creates duplicate copies of all DOM Elements."
To me this is completely the opposite that you are saying.
Independently of how the clone() should work, then please explain why I get two completely different behaviours with this two snippets of code:
===========================
<div class="templateDiv">TEMPLATE</div>
===========================
var templateDiv = $('.templateDiv');
var templateDivCopy = templateDiv.clone().get(0); // templateDivCopy is a reference of the original templateDiv
and
var templateDivCopy = $('.templateDiv').clone().get(0);
with the first one, if I do templateDivCopy.innedHTML = "ANY TEXT", then this sets the innerHTML of BOTH elements; but in the second case, if I do the same, only the copy is affected!
>Another cause of apparent bug is that you clone an object leaving it
>with the same id of its source
>with the same id of its source
That's not really what I'm doing, but I accept it was a good example.
thanks
On 9/30/06, Renato Formato <[EMAIL PROTECTED]> wrote:
> Anyway, why a clone() affects the object. Cloning should only create a
> copy object, not affect the state of the original one.
>
I think it is because you may want to chain methods on the cloned object.
If clone() does not substitute the cloned object with the original one,
you could not call methods on it, as the underlaying object would remain
the original one.
Anyway clone() does not modify the original DOM element. It just switch
the DOM element in your jquery object.
Another cause of apparent bug is that you clone an object leaving it
with the same id of its source. After cloning, you should change the id
of the copy or you will be unable to select the original object again.
If you want to keep a reference to the original jQuery object, Jorn
suggestion is perfect.
Renato
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
