2013-05-03 59 views
0

这让人感到无聊。我试图做一个简单的追加从一个元素到另一个:无法将DOM元素移动到其他位置

  var contentBlob = $('<div></div>', { 
       "id" : "content-blob", 
       "css" : { 
        "display" : "none", 
        "color" : "red" 
        } 
      }); 

      // this guy gets a full xhtml page with head and body. 
      // I don't want to use load() 
      model.getHtml(indexUrl, function(response){ 
        if(response != 0){ 
         contentBlob.html(response); 
        } 
      }); 

      contentBlob.appendTo('body'); 
      //I've verified the that the contentBlob (#content-blob) is in the body 

      // This should be super simple. No matter what I do, Its not appending 
      // the ul. 
      $('#content-blob > ul').appendTo('#contents-index-actual-index'); 

我已经特里普尔检查选择,一切看起来合法的。一个有趣的事情是,如果我不将ul添加到选择器,#content-blob将会追加。

+1

getHTML是异步的吗?如果是这样,那么''('#content-blob> ul')。appendTo(...'在'contentBlob'已经被填充之前就运行了,我会认为它是异步的,因为回调。一行代码到回调函数 – 2013-05-03 00:47:05

+0

omg,谢谢,那个工作!我昨天晚上分开了! – 4m1r 2013-05-03 17:20:21

+0

不客气。 – 2013-05-03 17:21:20

回答

0

Squint是对的。异步获取发生在appendTo之后。

相关问题