user007
user007

Reputation: 3243

jQuery - clone and append to textarea

I am trying to clone a div and then I want to append it to a textarea when a button get clicked. But for some reason when I click on button I see:

[object Object]

Here is my code:

$('#save').click(function(e){
    e.preventDefault();
    var new_layout = $("#layout-builder").clone();
    jQuery('#for-save').append(new_layout); // also tried val()
});

Please tell me how do I clone a div and append it to a textarea

Upvotes: 0

Views: 618

Answers (2)

akbarbin
akbarbin

Reputation: 5105

When using clone() this can not be copied to text area. this more detail clone() and change append to val()

so please change your code into:

$('#save').click(function(e){
  e.preventDefault();
  var new_layout = $("#layout-builder").html();
  jQuery('#for-save').val(new_layout);
});

Upvotes: 1

Adil Shaikh
Adil Shaikh

Reputation: 44740

use .html()

jQuery('#for-save').append(new_layout.html());

or to append outerHtml

jQuery('#for-save').append(new_layout[0].outerHTML);

Upvotes: 2

Related Questions