tags:

views:

39

answers:

1

i got these two in the DOM:

<div id="buffert">
      <span class="left"><a>link</a><a>link</a></span>
      <span class="right">Some text<span>title</span></span>
</div>

<div id="final">
      <span class="left">&nbsp;</span>
      <span class="right">&nbsp;</span>
</div>

i want to move whatever elements within the div#buffert span.left and span.right to div#final span.left and span.right.

i tried:

 $('div#final span.left').append($('div#buffert span.left'));
 $('div#final span.left').append($('div#buffert span.left.children'));
 $('div#final span.left').append($('div#buffert span.left.children()'));

but it doesnt work.

could someone help me?

+3  A: 

There are numerous ways to accomplish what you're asking...these are just a few.

With the structure being identical, why not just replace the HTML?

$("#final").html( $("#buffert").html() );

If you wanted to append them to the #final element, you would use $.appendTo():

$("#buffert .left, #buffert .right").appendTo("#final");

Or you could move the children themselves over (and not merely the HTML)

$("#final .left").html("").append( $("#buffert .left").children() );
Jonathan Sampson
By using the html() method you will loose any events bound on the original elements.
PetersenDidIt
Correct, which is why I provided the last example in the solution.
Jonathan Sampson
wow jonathan...u have helped me a lot since i registered...u have a lot of php/html experience...what do you work with?
weng
Crayons mostly ;) Hehe. I'm glad that I've been able to help you out.
Jonathan Sampson