JQuery Bug? error when clone from selector if there has js

JQuery Bug? error when clone from selector if there has js

hi all,

the following code is work in ie, but error in firefore, is it a bug if the selector element have javascript?
<script language="javascript">
   var idx = 2;
</script>

<div id="id1">
   <p>
      <script language="javascript">
         if (idx == 2) {
            document.write(" aaaaaaa");
         }
      </script>
   </p>
</div>

<hr>

<div id="id2"></div>
<!------------------------------------------------------>

<script language="javascript">
   $("#id1").clone().appendTo("#id2");
</script>


ie display like following:
123 aaaaaaa
----------------------------
123 aaaaaaa


ff display like following:
123 aaaaaaa
----------------------------
123 aaaaaaa
aaaaaaa


anyone know y and how to fix it?
many thank