I'm trying to figure out js, I can't figure out how to output html, css and js code as text. Example:

document.write('<b>hello</b>') //на странице должно вывестись <b>hello</b> 
  • and displayed ...? - Igor
  • It is displayed simply hello without tags - VCM
  • First, document.write ('<b> hello <\ / b>') - escape slashes. Secondly, the browser does not show the source code, but shows the interpreted one. - Mik
  • Well, how to get it to display the source code? Shielded? - VCM
  • document.body.textContent = '<b>hello</b>'; - Deonis

1 answer 1

Try this

 document.write('<xmp><b>hello</b></xmp>'); 

But the xmp tag is deprecated. You can use the code

 document.write('<code>&ltb&gthello&lt/b&gt</code>'); 
  • It works, thank you very much - VCM
  • @ConstantineVolochshuk, please. - LEQADA 5:56