0

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?

Actimia
  • 135
  • 2
  • 3
  • 9
  • 1
    duplicate -->`http://stackoverflow.com/questions/8994516/html-css-best-practice-for-preserving-white-space-on-certain-elements` – rt2800 Feb 03 '14 at 05:48
  • Thanks, that solved my problem! I was unsure what to search for :) – Actimia Feb 03 '14 at 05:52

0 Answers0