You may want to use the appendTo
function (which adds to the end of the element):
(您可能想要使用appendTo
函数(添加到元素的末尾):)
$("#source").appendTo("#destination");
Alternatively you could use the prependTo
function (which adds to the beginning of the element):
(或者你可以使用prependTo
函数(它添加到元素的开头):)
$("#source").prependTo("#destination");
Example:
(例:)
$("#appendTo").click(function() { $("#moveMeIntoMain").appendTo($("#main")); }); $("#prependTo").click(function() { $("#moveMeIntoMain").prependTo($("#main")); });
#main { border: 2px solid blue; min-height: 100px; } .moveMeIntoMain { border: 1px solid red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="main">main</div> <div id="moveMeIntoMain" class="moveMeIntoMain">move me to main</div> <button id="appendTo">appendTo main</button> <button id="prependTo">prependTo main</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…