如何将一个元素移动到另一个元素中? [英] How to move an element into another element?

查看:43
本文介绍了如何将一个元素移动到另一个元素中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个 DIV 元素移到另一个内部.比如我要移动这个(包括所有孩子):

...

进入这个:

...

所以我有这个:

<div id="源">...

解决方案

曾经尝试过纯 JavaScript... destination.appendChild(source); ?

onclick = function(){ destination.appendChild(source);}

div{ margin: .1em;}#destination{ 边框:1px 实心红色;}#source {border: 实心 1px 灰色;}

<身体><div id="目的地">###

<div id="源">***

</html>

I would like to move one DIV element inside another. For example, I want to move this (including all children):

<div id="source">
...
</div>

into this:

<div id="destination">
...
</div>

so that I have this:

<div id="destination">
  <div id="source">
    ...
  </div>
</div>

解决方案

Ever tried plain JavaScript... destination.appendChild(source); ?

onclick = function(){ destination.appendChild(source); }

div{ margin: .1em; } 
#destination{ border: solid 1px red; }
#source {border: solid 1px gray; }

<!DOCTYPE html>
<html>

 <body>

  <div id="destination">
   ###
  </div>
  <div id="source">
   ***
  </div>

 </body>
</html>

这篇关于如何将一个元素移动到另一个元素中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆