Question

Im looking for a way to move a object (a banner) as a string to a textarea so that the user has it easy to copy past its content:

var object_sting = $('<div>').append($('#customized_banner').clone()).remove().html();
$('#customized_banner_code').attr("innerHTML", object_sting);

I'm trying to solve it with these two lines. The first results in a string and the second should add the string into the textarea. It unfortunately dosen't add it.

Strange is that both lines in itself do what they are expected to. the first does load the object in the variable as string. And the second does add text into the textarea if I replace the object_string with string.

Thanks for your hint! Markus

Was it helpful?

Solution

you can try:

$('#customized_banner_code').val(object_sting);

or even

$('#customized_banner_code').val(escape(object_sting));

OTHER TIPS

You are adding the HTML code as code inside the textarea. Try to add it as text instead:

var object_sting = $('<div>').append($('#customized_banner').clone()).remove().html();
$('#customized_banner_code').val(object_sting);

Looks like you delete the whole thing before you get the string. Do this:

var div = $('<div>').append($('#customized_banner').clone());
var object_sting = div.html();
div.remove();
$('#customized_banner_code').val( object_sting );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top