Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving the content of a DIV to another DIV with jQuery

http://www.frostjedi.com/terra/scripts/demo/jquery02.html

According to this link elements can be moved around by doing $('#container1').append($('#container2')). Unfortunately, it doesn't seem to be working for me. Any ideas?

like image 522
neubert Avatar asked Mar 26 '12 05:03

neubert


People also ask

How do I move a div to another div using jQuery?

All you have to do is select the element(s) you want to move, then call an “adding” method such as append() , appendTo() or prepend() to add the selected elements to another parent element. jQuery automatically realises that the element(s) to add already exist in the page, and it moves the element(s) to the new parent.

What is .next in jQuery?

next() The next() is an inbuilt function in jQuery which is used to return the next sibling of the selected element. Siblings are those having same parent element in DOM Tree.


1 Answers

See jsfiddle http://jsfiddle.net/Tu7Nc/1/

You must append not your div exactly, but your div's content(inner HTML) with Jquery's html() function.

HTML:

<div id="1">aaa</div>
<div id="2">bbb</div>​

Jquery:

$("#1").append($("#2").html());

Result:

aaabbb
bbb
like image 136
Chuck Norris Avatar answered Oct 08 '22 04:10

Chuck Norris