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

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

In IE when I insert text into a

 tag the newlines are ignored:





        
11条回答
  •  [愿得一人]
    2020-12-10 12:44

    Content inside the

     tag should not be considered HTML.

    In fact, the point of

     tag is so that it does display formatted text.

    Using the innerText property is the correct way to modify the content of a

     tag.

    document.getElementById("putItHere").innerText = "first line\nsecond line";
    

提交回复
热议问题