Patrick Reck
Patrick Reck

Reputation: 11374

Copy DIV content to another DIV

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

Answers (4)

Juan Gonzales
Juan Gonzales

Reputation: 1977

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

Upvotes: 0

stlvc
stlvc

Reputation: 823

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

http://api.jquery.com/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.

Upvotes: 4

jacktheripper
jacktheripper

Reputation: 14219

$('#two').html($('#one').html());

See this live example

Upvotes: 0

Danil Speransky
Danil Speransky

Reputation: 30453

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

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

Upvotes: 3

Related Questions