Solution 1 :

Since you want to replace n with <br> tag, you can try:

var obj = {
  "body": "Bla bla blan- Bla bla bla"
};

var div = document.createElement("div");
div.innerHTML = obj.body.replace(/n/g, '<br>');

document.body.appendChild(div);

Or just using <pre> tag:

var obj = {
  "body": "Bla bla blan- Bla bla bla"
};

var pre = document.createElement("pre");
pre.innerHTML = obj.body;

document.body.appendChild(pre);

Problem :

I have some JSON:
"body": "Bla bla blan- Bla bla bla"

I put it in a DIV

var card_body = document.createElement("DIV");
card_body.innerHTML = obj.body;`

The result:

<div>
"Bla bla bla - Bla bla bla"
</div>

I have tried to make it a PRE instead of a DIV but that means it can’t be styled as I want it.

I have tried to replace all /n with <br>, but that does not work either.

Please help

Comments

Comment posted by Lain

You could add

By

Leave a Reply

Your email address will not be published. Required fields are marked *