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>');


Or just using <pre> tag:

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

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


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:

"Bla bla bla - Bla bla bla"

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


Comment posted by Lain

You could add


Leave a Reply

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