I have a simple web page where I dynamically add new text elements with a JS function. However I want the displayed text to retain its leading whitespace (so I can do print several lines with controlled indentation). It is currently rendered without it (I can still see it in the inspector). This is my message adding function: (The first parameter is a CSS hint)
function printMessage(cls, text){
var cont = document.getElementById('container');
cont.insertAdjacentHTML('beforeend', '<div class="' + cls + '">' + text + '</div>');
window.scrollTo(0,document.body.scrollHeight);
}
A typical call might be printMessage('help', ' Type help to get help');
. The two leading spaces in the second argument are not shown. Any clues?