jQuery 将内容从一个隐藏的 div 移动到另一个显示的 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3242820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
move content from one hidden div to another displayed div
提问by user384080
how do i move content from one hidden div to another displayed div using jquery?
如何使用 jquery 将内容从一个隐藏的 div 移动到另一个显示的 div?
say i have div1 with display style is none and another div "div2" with display style block.
假设我有一个显示样式为 none 的 div1 和另一个显示样式块的 div“div2”。
how do I move the content from div1 to div2 and clear div1?
如何将内容从 div1 移动到 div2 并清除 div1?
回答by D.Tate
.contents()
may be what you need:
.contents()
可能是你需要的:
$('#div1').contents().appendTo('#div2')
Take note that it will move(not copy) the inner elements from one div to the other.
请注意,它会将内部元素从一个 div移动(而不是复制)到另一个。
回答by Stephen Wrighton
Why not just show the hidden div and hide the displayed one?
为什么不只显示隐藏的 div 并隐藏显示的 div?
But to answer your question.
但是要回答你的问题。
$('#div2').html($('#div1').html());
$('#div1').html('');
回答by meder omuraliev
$( $('#div1').html() ).appendTo('#div2')