appendTo and remove not working in IE8

The following snippet of html and jquery works in: Firefox, Safari and Chrome, both in OSX and XP (all browsers latest production updates.

I'm using the java debugger in safari, firefox and IE8

But in IE8, the contents of CCC is not moved!! I do not have IE6 or IE7 to test with.

<html>
<head>   </head>
<body>
   <div class="AAA">
      <div class="BBB">  </div>
   </div>

   <div class="CCC">
      <div id="0">   <img src="image/..." />  </div>
      <div id="1">   <img src="image/..." />  </div>
   </div>
</html>

jquery code is in a separate file:

jQuery(window).load(function() {
   // move div's contained within class="CCC" to class="BBB"
   $('.CCC div).each(function() {
      $(this).appendTo('.AAA .BBB');
});

At the completion of this function, class "CCC" will have no content.

I also tried remove. I get the same results in IE8 (not working).

After executing "var temp" line, each div in the loop should be removed. I'm looking in the debugger "html view" to verify this.

$(.CCC div).each(function() {
    var temp = ('.CCC div:eq(0)').remove();
    temp.appendTo('BBB');
});

我认为你错过了$

 var temp = $('.CCC div:eq(0)').remove();

You will want to do this when the document is ready and not on window load. Also, console.log anywhere in your code will "kill" JS if you are using Firefox without Firebug and probably (although i'm not sure) IE.

$(document).ready(function() {
   // move div's contained within class="CCC" to class="BBB"
   $('.CCC div').each(function() {
      $(this).appendTo('.BBB'); //.AAA is not necessary if you want to append to all instances of .BBB
});
链接地址: http://www.djcxy.com/p/23030.html

上一篇: 加载并执行脚本的顺序

下一篇: appendTo并删除不在IE8中工作