开发者

appendTo and remove not working in IE8

开发者 https://www.devze.com 2023-01-24 14:27 出处:网络
The following snippet of html and jquery works in: Firefox, Safari and Chrome, both in OSX and XP (all browsers latest production updates.

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>开发者_如何学JAVA;
      <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');
});


i think you are missing a $

 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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号