tags:

views:

44

answers:

3

Hi there,

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?

A: 
$( $('#div1').html() ).appendTo('#div2')
meder
error: Microsoft JScript runtime error: Object doesn't support this property or method
fixed. if you are getting that runtime error, chances are it's not our code and it's something else on your end.
meder
A: 

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);
RPM1984
getting this error: htmlfile: Unknown runtime error
sounds like something else on your page. i created a simple page with nothing but two div's and the above code works fine (as does everyone else's similar answers)
RPM1984
please note the form is on MVC framework.. it might behave differently.. thanks
javascript/jquery deals with html and the DOM only (client-side), it has no bearing on what web server technology (web forms, mvc)
RPM1984
A: 

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

But to answer your question.

 $('#div2').html($('#div1').html());
$('#div1').html('');
Stephen Wrighton
htmlfile: Unknown runtime error
@ronald-yoh - Are you including jQuery in the page? when your question is tagged with jquery, there is an assumption you're using it.
Nick Craver
yes.. I'm using jquery