String template - new line doesn't show

后端 未结 1 352
终归单人心
终归单人心 2021-01-28 12:46

I\'m trying to use a template string to update infoDiv\'s text and for some reason all this text is in one line. What am I doing wrong? None of these solutions work - they\'re j

相关标签:
1条回答
  • 2021-01-28 13:26

    Style the div with white-space CSS property.

    const counter = 22;
    const time_minutes = 60;
    
    infoDiv.textContent = `Hi!
    It's a ${counter} question quiz.
    It takes about ${time_minutes} minutes to solve it.
    Are you ready?`
    <div id="infoDiv" style="white-space: pre-wrap"></div>

    0 讨论(0)
提交回复
热议问题