How to count newlines in Internet Explorer?

Hey there. I am making my syntax shortcut for Javascript and CSS and I am having a problem with Internet Explorer (big surprise). I grab the entire contents of the tag code.block(example below) with innerHTMLand .split("\n"), which produce each line. This works great except IE.

I tried using innerTextand .split("\r\n")also without success. Can anyone recommend a solution? If that matters, tags code.blockhave style white-space:pre-wrap.

<code class="block css">div#randomBarsDemo {
    width:175px;
    height:200px;
}

div#randomBarsDemo div {
    background-color:#111;
    width:100%;
}</code>
+3
source share
2 answers

, ( IE8 Windows, ) - innerText , \r <br/> innerHTML

var el = document.getElementById('target');
el.innerHTML = el.innerText.replace(/\r/,"<br/>");

, ​​, .split() <BR>. <BR>, <br/> HTML Internet Explorer.

, , innerText \r s, \n. , , , , .

0

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


All Articles