Bijan Zand
Bijan Zand

Reputation: 51

jQuery just clone VALUE element

I need to just clone a element's value to an another element

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

I want print value on div

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

jQuery : With this, all a tag have been cloned ! I want just clone the value of element !

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

Thanks for your help

Upvotes: 0

Views: 20

Answers (1)

Bhuwan
Bhuwan

Reputation: 16855

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

However there are several ways you can achieve this

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>

Upvotes: 2

Related Questions