How can I insert new line/carriage returns into an element.textContent?

前端 未结 9 2130
野的像风
野的像风 2020-11-27 14:44

As silly as it may sound, I still haven\'t found an appropriate answer.

Let\'s say I want to dynamically create a new DOM element and fill up its textContent/innerTe

9条回答
  •  情歌与酒
    2020-11-27 15:29

    You can concatenate the strings...

    h1.innerHTML += "...I would like to insert a carriage return here...
    "; h1.innerHTML += "Ant the other line here...
    "; h1.innerHTML += "And so on...
    ";

    jsFiddle.

提交回复
热议问题