最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Copy DIV content to another DIV - Stack Overflow

programmeradmin1浏览0评论

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());

However i wasn't able to make it work out

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());

However i wasn't able to make it work out

Share Improve this question edited Sep 4, 2012 at 6:59 Danil Speransky 30.5k6 gold badges69 silver badges78 bronze badges asked Jul 31, 2012 at 15:24 Patrick ReckPatrick Reck 11.4k11 gold badges56 silver badges88 bronze badges 1
  • 1 Remember: $('.buffer') may select multiple elements. – gen_Eric Commented Jul 31, 2012 at 15:27
Add a ment  | 

4 Answers 4

Reset to default 4

Assuming your selectors are correct, you should put your code in the .ready() Event.

http://api.jquery./ready/

So something like:

jQuery(document).ready(function() {
    jQuery('.buffer').html(jQuery("#beskeder_vis").html());
}

Otherwise jQuery won't be able to find your elements, since the DOM isn't loaded, when your function is executed.

You should bind event handler on ready event. See documentation: ready funciton

$(document).ready(function () {
  $('.buffer').html($("#beskeder_vis").html());
});
$('#two').html($('#one').html());

See this live example

It works for me. It may have something to do with the jquery version your using Proof jsfiddle

发布评论

评论列表(0)

  1. 暂无评论