jack
jack

Reputation: 403

Jquery - passing a duplicate of a <div> to another

When passing the contents of a <div> to another <div> with jquery as below, the original is removed. Is there a way to do this and still retain the original?
Example Here - I want the document to read Item One, Item Two, Item One.

   function display() {
    $('#display').html($('#ItemOne'));
}

display();

Upvotes: 2

Views: 135

Answers (3)

Topera
Topera

Reputation: 12389

Change to

function open() {
    $('#display').html($('#ItemOne').clone());
}

See: jsfiddle

Upvotes: 1

Patricia
Patricia

Reputation: 7802

 $('#display').html($('#ItemOne').html());

add .html()

Upvotes: 2

js1568
js1568

Reputation: 7032

use clone()

http://docs.jquery.com/Clone

function display() {
    $('#display').html($('#ItemOne').clone());
}

display();

Upvotes: 4

Related Questions