function pocan288 () { const str = document.getElementsByClassName("txtin")[0].value; const parts = str.split(' '); const output = parts.(part => `<p>${part}</p>`).join(''); element value ='txtout'; } <p> Исходный текст</p> <textarea class='txtin'> </textarea> <p><input type="submit" onclick="pocan288()"></p> <p> Текст с абзацами </p> <textarea class='txtout'> </textarea> 
  • Your code is not valid at all, what kind of parts.(part =>...) code parts.(part =>...) and element value = 'txtout' - Vasily Barbashev

1 answer 1

For example, this option

 function check() { const strIn = document.getElementsByClassName("txtin")[0].value; const strOut = document.getElementsByClassName("txtout")[0]; console.log(strIn); const parts = strIn.split(' '); const output = parts.map(part => `<p>${part}</p>`).join(''); console.log(output); strOut.value = output; } 
 <p> Исходный текст </p> <textarea class='txtin'></textarea > <p><input type="submit" onclick="check();"></p> <p>Текст с абзацами </p> <textarea class='txtout'></textarea> 

  • Grateful for the help. In order for the program to work correctly, you need to change the code to: const output = parts.join ('\ n'); - oleja
  • I just made it workable, how you need to transform it, it's up to you. Good codding! - Vasily Barbashev