Reputation: 11374
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
Upvotes: 1
Views: 3780
Reputation: 1977
It works for me. It may have something to do with the jquery version your using Proof jsfiddle
Upvotes: 0
Reputation: 823
Assuming your selectors are correct, you should put your code in the .ready() Event.
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.
Upvotes: 4
Reputation: 30453
You should bind event handler on ready event. See documentation: ready funciton
$(document).ready(function () {
$('.buffer').html($("#beskeder_vis").html());
});
Upvotes: 3