Displaying text in textarea with formatting in place (e.g.
)

How can I display a wall of text example:

hello
<br>
how is your day
<br>
123

Into

hello

how is your day

123

I’m trying to display these into a textarea field as well.

I’ve tried with this $('<textarea />').html(theString).text(); but it does not display my desired result

Edit:

Current code:

function displayCustom (data) {
var myString= data.getAttribute("data-contentDetails");
$('#textareaContent").html(myString);
}

Answer

this is not possible to do this with textarea. you can use content editable div

var theString = `Hello.<br>Hi.<br>Hey, <strong>user</strong> <span style="color: red">Logout</span>.`

// in pure js
document.getElementById('textareaContent').innerHTML = theString;

// OR in jQuery
$('#textareaContent').html(theString)
div {
    width: 250px;
    height: 150px;
    border: 1px solid #ababab;
    padding: 8px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div id="textareaContent" contenteditable="true"></div>

UPDATE

if you have to use textarea and just need to use <br /> (you couldn’t use another HTML tag as a text) you can use:

var myString = `Hello<br>Hi<br>Hey, use`

$('#text').html(myString.replace(/<br>/g, 'n'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<textarea id="text"></textarea>