将DIV内容复制到另一个DIV [英] Copy DIV content to another DIV
本文介绍了将DIV内容复制到另一个DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在使用页面加载页面时将DIV1的内容复制到DIV2?我已经尝试过
How do i copy the contents of DIV1 to DIV2 on load of the page using jquery? I've tried
$('.buffer').html($("#beskeder_vis").html());
但是我没办法解决
推荐答案
假设选择器正确,则应将代码放入.ready()事件中.
Assuming your selectors are correct, you should put your code in the .ready() Event.
所以像这样:
jQuery(document).ready(function() {
jQuery('.buffer').html(jQuery("#beskeder_vis").html());
}
否则,由于在执行函数时未加载DOM,因此jQuery将无法找到您的元素.
Otherwise jQuery won't be able to find your elements, since the DOM isn't loaded, when your function is executed.
这篇关于将DIV内容复制到另一个DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文