Problems with jQuery 1.6.4 cloning in Internet Explorer 7

I am using jQuery v1.6.4. Here is a test case for my problem:

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
         <script type="text/javascript" src="jquery.js"></script>
    </head>
    <body>

        <div id="container"></div>
        <div id="clone-tpl">I am a clone template</div>

        <script type="text/javascript">
              $(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')); 
            });
         </script>  
        </body>
    </html>

In Mozilla Firefox and Internet Explorer 9, it works as expected: it clones clone-tpl two times, changes its identifier, and adds clones to the div container. The container container remains intact. The alert log is as follows:

<div id="other0.7574357943876624">I am a clone</div>
clone-tpl
<div id="other0.7574357943876624">I am a clone</div><div id="other0.1724491511655708">I am a clone 2</div>
clone-tpl

But in Internet Explorer 7, he messed up everything with clone2, look what warns:

<DIV id=other0.1851332940530379>I am a clone</DIV>
clone-tpl
<DIV id=other0.1851332940530379>I am a clone</DIV><DIV id=clone-tpl>I am a clone 2</DIV>
other0.6041996510541515

I have no idea how alert($('#clone-tpl').attr('id'))can suddenly give something else than clone-tpl? In the end, if I select an element with the id attribute clone-tpl, the id attribute MUST be a clone-tpl, but it is not!

What's wrong? Why does IE7 change the identifier of the clone source if I create a second clone?

, jQuery v1.4.2, IE7 .

​​jQuery v1.6.4? ?

P.S. 1.4.2, 1.6 , jQuery: http://bugs.jquery.com/ticket/5684?version=10.

+5
1

IE.

- IE, . , , IE .

.

function shimNode(jqObj){   
    var html = jqObj.html();
    var id = jqObj[0].id;
    var classes = jqObj.attr('class');
    var styles = jqObj.attr('style');
    var pattern = ['<div id="',id,'" class="',classes,'" style="',styles,'">',html,'</div>'].join('');

    return jQuery(pattern);
}
+2

All Articles