JSON:
{"data": {
"heading": "Module 2: Discussion Boards 1",
"description": "Students were asked to post to the Discussion board the responses they gathered from interviewing an experienced online instructor.\n Students were then asked to read the posts and offer feedback to their colleagues.",
"tabs": {
"tabItem": [
{
"value": "Edgar and Amy Conflict"
},
{
"value": "Oliver's Document"
},
{
"value": "Two Professors?"
}
]
}
}
}
Javascript:
var actual_JSON = JSON.parse(response);
document.getElementById("heading").innerHTML = actual_JSON.data.heading;
document.getElementById("description").innerHTML = actual_JSON.data.description;
Result
The new line (\n
) does not work. I have tried \\n
but to no avail.
When I tried var actual_JSON = JSON.strigify(response);
in the console.log I can get the new line if I replace \n
with <br>
in the JSON but then it does not work as an object so the rest of the code breaks down.
I have seen many posts in this regard and tried the solutions presented, but I'm missing something.
Thanks for any help!
` & address the consequences or apply `white-space: pre-line;` to the element as a last resort. – Alex K. Mar 29 '17 at 15:25
tags?](http://stackoverflow.com/q/784539/218196) – Felix Kling Mar 29 '17 at 15:41
in the data and then have HTML display it. However when I do that, the tags show up as regular text in the HTML page and are not being interpreted as code. – user2191049 Mar 29 '17 at 17:21
solution. The issue was in two places with different code. The second piece of code was appending a new para element and that's why the text was being passed to it via textContent, which does not render tags and instead shows them as is. Converted that to innerHTML as well and all is well. Thanks fo rall the help guys! – user2191049 Mar 30 '17 at 13:32