user384080
user384080

Reputation: 4692

move content from one hidden div to another displayed div

how do i move content from one hidden div to another displayed div using jquery?

say i have div1 with display style is none and another div "div2" with display style block.

how do I move the content from div1 to div2 and clear div1?

Upvotes: 15

Views: 26126

Answers (4)

D.Tate
D.Tate

Reputation: 2309

.contents() may be what you need:

$('#div1').contents().appendTo('#div2')

Take note that it will move (not copy) the inner elements from one div to the other.

Upvotes: 22

meder omuraliev
meder omuraliev

Reputation: 186562

$( $('#div1').html() ).appendTo('#div2')

Upvotes: 0

Stephen Wrighton
Stephen Wrighton

Reputation: 37819

Why not just show the hidden div and hide the displayed one?

But to answer your question.

 $('#div2').html($('#div1').html());
$('#div1').html('');

Upvotes: 11

RPM1984
RPM1984

Reputation: 73112

First you'd need to get the HTML from DIV1, and then set the HTML in DIV2.

Use the get/set operations available on the .html() selector.

Like this:

var div1Html = $('#div1').html();
$('#div2').html(div1Html);

Upvotes: 0

Related Questions