Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery 1.6.4 cloning problems in Internet Explorer 7
    text
    copied!<p>I am using jQuery v1.6.4. Here is the test case for my problem:</p> <pre><code> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;div id="clone-tpl"&gt;I am a clone template&lt;/div&gt; &lt;script type="text/javascript"&gt; $(function(){ var clone = $('#clone-tpl').clone(); clone.attr('id','other'+Math.random()); clone.text('I am a clone'); $('#container').append(clone); alert($('#container').html()); alert($('#clone-tpl').attr('id')); var clone2 = $('#clone-tpl').clone(); clone2.attr('id','other'+Math.random()); clone2.text('I am a clone 2'); $('#container').append(clone2); alert($('#container').html()); alert($('#clone-tpl').attr('id')); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>In Mozilla Firefox and Internet Explorer 9 it works as expected: clones clone-tpl two times, changes id and appends the clones to the container div. The container div stays intact. The alert output log is the following:</p> <pre><code>&lt;div id="other0.7574357943876624"&gt;I am a clone&lt;/div&gt; clone-tpl &lt;div id="other0.7574357943876624"&gt;I am a clone&lt;/div&gt;&lt;div id="other0.1724491511655708"&gt;I am a clone 2&lt;/div&gt; clone-tpl </code></pre> <p>But on Internet Explorer 7 it messes things up with the clone2, look what alert says:</p> <pre><code>&lt;DIV id=other0.1851332940530379&gt;I am a clone&lt;/DIV&gt; clone-tpl &lt;DIV id=other0.1851332940530379&gt;I am a clone&lt;/DIV&gt;&lt;DIV id=clone-tpl&gt;I am a clone 2&lt;/DIV&gt; other0.6041996510541515 </code></pre> <p>I have no idea, how <code>alert($('#clone-tpl').attr('id'))</code> could suddenly give something else than clone-tpl? After all, if I select element by id attribute clone-tpl, the id attribute MUST be clone-tpl, but it is not!</p> <p>What is wrong? Why does IE7 change id of the cloning source if I create a second clone?</p> <p>By the way, if I revert back to jQuery v1.4.2, IE7 starts cloning normally.</p> <p><strong>Is it a bug in jQuery v1.6.4? Is there any workaround for it?</strong></p> <p>P.S. I really would like to avoid reverting to 1.4.2 because 1.6 has some useful features which help me to overcome some other jQuery bug: <a href="http://bugs.jquery.com/ticket/5684?version=10" rel="nofollow">http://bugs.jquery.com/ticket/5684?version=10</a> .</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload