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
4 Answers
Reset to default 4Assuming 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