F
F
freeman02042018-03-15 16:55:09
JavaScript
freeman0204, 2018-03-15 16:55:09

How to format the text copied by the .text(); method?

var text1 = $(".wrap_info_calc p").text();
    $(".wrap_box_info textarea").text(text1);

I copied all the paragraphs from the block and pasted them into the textarea. They are in one line.
How can I format them, add spaces, line breaks, and so on. where do i need it?
Or maybe in the textarea you can insert text with tags at once? The .clone() method does not insert the structure itself into the textarea.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-03-15
@freeman0204

with hyphens,
each <p>will be on a new line

var text1 = $(".wrap_info_calc p").map(function(){
  return $(this).text();
}).get().join('\n');
$(".wrap_box_info textarea").text(text1);

check
and if not what you wanted, then throw off at least an approximate layout code .
var text1 = $(".wrap_info_calc p").map(function(){
  return $(this.innerHTML.replace('<br>', '\n')).text();
}).get().join('\n');
$(".wrap_box_info textarea").text(text1);

need to check

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question