[英]Moving Div and Content into Another Div
我嘗試使用以下方法將我的 div 及其內容移動到另一個 div:
<script>
document.getElementById('#header').appendChild(
document.getElementById('#live')
);
</script>
和
<script>
$("#header").append($("#live"))
);
</script>
但我不能移動 div 我所做的最好的就是移動一些文本。
幫助。
如果您使用的是 jQuery,您想要的代碼是
$('#div1Content').appendTo('#div2');
看看這里的演示, http://jsfiddle.net/nwe44/we2cN/
嘗試
$('#live').appendTo('#header');
或者,
var live = $('#live').detach();
//do stuff
live.appendTo('#header');
detach() 將其從 DOM 中刪除,但將其保留在 memory 中,然后您可以將其 append 到其新父級。
使用 jQuery (您似乎在您的一個示例中使用它),您可以使用appendTo
方法(請參閱文檔):
$("#live").appendTo("#header");
這會將#live
元素移動到#header
元素中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.