Luth Hizb Luth Hizb - 16 days ago 5
HTML Question

Javascript : Return .innerHTML as syntax

I have a little problem here...

This is my code

<html>
<textarea id="text">
<h2>Text Here...</h2>
</textarea>

<div id="preview">

</div>
</html>

<script>
var syntax = document.getElementById("text").innerHTML;
document.getElementById("preview").innerHTML = syntax;
</script>


The problem is the
preview
shows
<h2>Text Here...</h2>
instead of
Text Here...
with
h2
font.

Thanks

Beginner Programmer

Answer

Just change your script :

  var syntax = document.getElementById("text").innerHTML;
  document.getElementById("preview").innerHTML = syntax;
 <div id="text">
  <h2>Text Here...</h2>
 </div>

 <div id="preview">

 </div>