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
use .html()
jQuery('#for-save').append(new_layout.html());
or to append outerHtml
jQuery('#for-save').append(new_layout[0].outerHTML);
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);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.