Inserting a newline into a pre tag (IE, Javascript)

前端 未结 11 1854
走了就别回头了
走了就别回头了 2020-12-10 12:34

In IE when I insert text into a

 tag the newlines are ignored:





        
11条回答
  •  眼角桃花
    2020-12-10 12:41

    I've found that innerHTML is processed before it is applied to the element, hence
    becomes a newline and multiple white spaces are removed.

    To preserve the raw text you must use nodeValue, for example;

    document.getElementById('pre_id').firstChild.nodeValue='    white space \r\n ad new line';
    

提交回复
热议问题