After seeing this answer I was trying to find a way to update the contents of a <pre>
tag and have the new-lines displayed using implicit new-lines (i.e. in the string literal). I tried setting various properties: innerHTML, innerText, textContent, nodeValue (after checking answers to this question) yet none seemed to have the white-space preserved.
I am aware I could use String.fromCharCode() - e.g. "Bob " + String.fromCharCode(10, 13) + "is "
... but wanted to find a way using the former syntax as well.
//Perfectly valid code
var foo = "Bob \
is \
cool.";
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('pre').textContent = foo;
});
<pre id="pre"></pre>
Is there a way to update the contents as desired?