我想把一些html元素复制或移动到另一个div元素中。
从这里:
<ul class='here'>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
<ul class='there'>
</ul>
改为:
<ul class='here'>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
<ul class='there'>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
或者这个:
<ul class='here'>
</ul>
<ul class='there'>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
将是伟大的都知道,提前感谢!
2条答案
按热度按时间c7rzv4ha1#
移动:
destination.appendChild( element )
副本:
destination.appendChild( element.cloneNode(true) )
一个一个三个一个一个一个一个一个四个一个一个一个一个一个五个一个
rdlzhqv92#
您可能需要使用appendTo函数(该函数添加到元素的末尾):
$("#here").appendTo("#there");
或者,您可以使用prependTo函数(添加到元素的开头):
$("#here").prependTo("#there");