Jacky
Jacky

Reputation: 433

Line breaks from data returned with REST

I have an object returned from REST service, one property of this object is supposed to be multiple lines of text, sometimes it's returned like the following in html (when viewing in dev tools)

 "this point will be as follows: ↵↵1- point info here ↵2- point2 info here

Sometimes it's displayed in html as:

this point will be as follows: 

1- point info here
2- points2 info here

But in fact, on the page, all rendered on one line.

When I add this text to an html element using the following code:

$("#elementId").html(myValue); //value is the text I mentioned above.

Where elementId is a paragraph tag. It's not setting the value as multilines of text.

Note: I am getting the values from SharePoint, I am still new to it. Any idea why .html() is not working right, specially in the second case?

Thanks

Upvotes: 0

Views: 553

Answers (1)

abc123
abc123

Reputation: 18773

Do a Replace

myValue = myValue.replace(/↵/g, "<br/>");

var myString = "this points will be as follows: ↵↵1- point info here ↵2- point2 info here";
myString = myString.replace(/↵/g, "<br/>")

console.log(myString);

Upvotes: 2

Related Questions