完全剪切和粘贴元素 [英] Completely cut and paste an element

查看:19
本文介绍了完全剪切和粘贴元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 jQuery 从一个位置剪切(完全,具有所有样式和属性)一个元素并将其粘贴到另一个位置(如 body)吗?

Can I cut (completely, with all styles and attributes) an element from a location and paste it in another location (like body) with jQuery?

另外,我想在旧位置放置一个字符串(或标签),因为我想在脚本末尾将其位置更改为旧位置.

Also, I want to place a string (or tag) in the old location, because I want to change its place to old location at the end of the script.

可以吗?怎么样?

推荐答案

appendTo() 会自动将匹配的元素从其当前位置移动到指定的容器中,这似乎是你想要的.

appendTo() will automatically move the matched elements from their current location to the specified container, which seems to be what you want.

您可以使用 after() 在移动元素之前插入新内容:

You can use after() to insert new content before moving the element:

$("#yourElement").after("<p>Element was there</p>").appendTo("body");

这篇关于完全剪切和粘贴元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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