\n is not creating a new line between text in javascript

前端 未结 4 1649
迷失自我
迷失自我 2021-01-17 05:41

I have a piece of JavaScript that is supposed to update a in my HTML:

var StringContent = ({
    \"a\": \'Some String a\',
    \"b\": \'Some string b\',
            


        
4条回答
  •  隐瞒了意图╮
    2021-01-17 06:01

    You should replace \n by
    since innerHTML takes an HTML string (in HTML, \n merges with adjacent spaces but does not produce a carriage return except for elements with the style white-space:pre-wrap as noted by MaxArt) :

    document.getElementById("overlaycontent").innerHTML = (
        StringContent.a + '
    ' + StringContent.b + '
    ' + StringContent.c, )

提交回复
热议问题