如何移动HTML元素 [英] How to move HTML element

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

问题描述

如何将HTML元素移动到另一个元素。请注意,我并不是指移动元素的位置。请考虑以下HTML代码:

How to move HTML element to another element. Note that, I don't mean moving element's position. Consider this HTML code:

<div id="target"></div>
<span id="to_be_moved"></span>

我想将to_be_moved移动到目标,以便目标现在具有子to_be_moved 。所以结果应该是这样的:

I want to move "to_be_moved" to "target" so "target" has child "to_be_moved" now. So the result should be like this:

<div id="target"><span id="to_be_moved"></span></div>

我在谷歌搜索过(特别是使用原型框架),但我所拥有的只是移动位置,不是我想要的。先谢谢。

I've searched in google (especially using prototype framework) but all I've got is moving position, not as I want. Thanks before.

推荐答案

document.getElementById('target').appendChild(  document.getElementById('to_be_moved') )

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆