0

Following code gets correctly formatted in HTML using Pre tag. The break tags get rendered correctly showing line breaks

<pre id="code">  package a;<br>import a.b;<br>import d.c;<br>public class Test{<br>}
     </pre>

Get the following output -

package a;
import a.b;
import d.c;
public class Test{
}

However if I load the same text using javascript

code.innerText = currentQuestion.code;

The break tag do not get rendered correctly and are shown as it is -

package a;<br>import a.b;<br>import d.c;<br>public class Test{<br>}

Can someone please help me here..thanks

Batman Rises
  • 597
  • 6
  • 9
  • Found the answer in another question here - https://stackoverflow.com/questions/451486/pre-tag-loses-line-breaks-when-setting-innerhtml-in-ie#:~:text=5%20Answers&text=Setting%20innerHTML%20fires%20up%20an,parser%20retains%20the%20hard%20returns. – Batman Rises Aug 27 '20 at 18:19
  • You need to set the `innerHTML`, not the `innerText` – Radvylf Programs Aug 27 '20 at 18:26

0 Answers0