Monday, February 21, 2011

Moving a div into another div

i have 2 main div:

    <div id="div1">
<div id="minidiv1">a</div>
<div id="minidiv2">b</div>
   </div>
   <div id="div2"></div>

I want move the minidiv1 into the div2 with jquery

how can i do?

From stackoverflow
  • You can simply append it to the div2, and it will change its location in the DOM:

    $('#minidiv1').appendTo('#div2'); 
    // or
    $('#div2').append('#minidiv1');
    

    The difference of the above two lines is what is returned, appendTo returns the #minidiv element, append will return the #div2 element.

    Use the one you find most useful if you want to make more actions (by chaining).

  • $('#minidiv1').appendTo('#div2');
    

    or

    $('#div2').append($('#minidiv1'));
    
  • $("#minidiv1").appendTo("#div2")
    

0 comments:

Post a Comment