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

前端 未结 9 2127
野的像风
野的像风 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:24

    None of the above solutions worked for me. I was trying to add a line feed and additional text to a

    element. I typically use Firefox, but I do need browser compatibility. I read that only Firefox supports the textContent property, only Internet Explorer supports the innerText property, but both support the innerHTML property. However, neither adding
    nor \n nor \r\n to any of those properties resulted in a new line. The following, however, did work:

    
    
    
    
    

    Original text.

提交回复
热议问题