jQuery只是克隆VALUE元素

问题描述 投票:0回答:1

我需要将元素的值克隆到另一个元素

<a id="button" href="">Google</a>

我想在div上打印值

 <div id="destination">Google</div>

jQuery:有了这个,所有a标签都被克隆了!我想要克隆元素的值!

 $("#button").clone().appendTo('#destination');

谢谢你的帮助

jquery html
1个回答
2
投票

clone() create a deep copy of the set of matched elements.

但是,有几种方法可以实现这一目标

1:Using html() jQuery

$('#destination').html($('#button').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="button" href="">Google</a>
<div id="destination"></div>

2:Using text() jQuery

$('#destination').text($('#button').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="button" href="">Google</a>
<div id="destination"></div>
© www.soinside.com 2019 - 2024. All rights reserved.