开发者

Moving Div and Content into Another Div

I 开发者_高级运维have tried to move my div and its contents to another div using such things as:

<script>
  document.getElementById('#header').appendChild(
    document.getElementById('#live')
  );
</script>

and

<script>
$("#header").append($("#live"))

  );
</script>

but i cant move the div the best i have done is move some text about.

Help.


If you're using jQuery, the code you want is

$('#div1Content').appendTo('#div2');

Have a look here for a demo, http://jsfiddle.net/nwe44/we2cN/


Try

$('#live').appendTo('#header');

alternatively,

var live = $('#live').detach();
//do stuff
live.appendTo('#header');

detach() removes it from the DOM but keeps it in memory, then you can append it to its new parent.


With jQuery (as you appear to be using it in one of your examples) you can use the appendTo method (see docs):

$("#live").appendTo("#header");

This moves the #live element into the #header element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜