Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move content from one hidden div to another displayed div

Tags:

jquery

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?

like image 255
user384080 Avatar asked Jul 14 '10 01:07

user384080


2 Answers

.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.

like image 158
D.Tate Avatar answered Sep 30 '22 21:09

D.Tate


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

But to answer your question.

 $('#div2').html($('#div1').html());
$('#div1').html('');
like image 41
Stephen Wrighton Avatar answered Sep 30 '22 21:09

Stephen Wrighton