MarcL
MarcL

Reputation: 83

jQuery copy content from one div into another

Working on my portfoilio script I'm now at the point where I want to copy the invisible <p>-content from one div into another one, but it doesn't work - any ideas how to solve this? Tried the

.clone() 

action, but it did not work until now.

Have a look AT MY FIDDLE

I want to copy inside the triggered .projecttile div into the #moreinfo div.

Upvotes: 0

Views: 17952

Answers (2)

Danny
Danny

Reputation: 1759

I think you want a separate div within your #moreinfo block, or otherwise when you copy the hidden details you will erase your [X] close button. I'm not sure whether you are trying to preserve the original dummy image or copy it over with the clicked one, but you can copy the hidden text with something like this (I'm using html instead of text in case you have markup in there).

$('#details').html($(this).parent().find('p').html());

I would also maybe add a class to the hidden <p> values and reference it by that, in case you wanted more than one <p> tag in there.

JSFiddle: http://jsfiddle.net/dshell/8FYrs/

Upvotes: 1

demonofthemist
demonofthemist

Reputation: 4199

You can use html() method to copy content inside html element & set it.

e.g.

var data = $('source_div').html();
$('target_div').html(data);

Upvotes: 3

Related Questions