InnerHtml and innerText destroy tabs in Internet Explorer

I want to take the contents of a text field and put it in <pre>. The problem is that if I set innerHTML -property to the value before textarea, all tabs and lines will be deleted in Internet Explorer. If I use innerText instead of innerHtml, I will get line breaks, but the tabs will still disappear. Works great in other browsers.

Is there a solution for this?

+3
source share
1 answer

Create the DOM node text:

pre.innerHTML= '';
pre.appendChild(document.createTextNode('A\tB\r\nC'));

Windows (\r\n) ( DOM , \n), - IE.

+5

Source: https://habr.com/ru/post/1759149/


All Articles