Search code examples
javascripthtmlhighlighthighlight.js

How to get plain text from highlight.js element?


I use highlight.js this way:

<div class="ex1" contenteditable="true">
   <pre>
      <code id="script_code" class="pgsql"></code>
   </pre>
</div>

User can edit the code. When user wants to save changes I need to get plain text.

When I get it:

var pscriptText = document.getElementById(divCodeView).innerHTML;

I see the tags. How to get the plain text?


Solution

  • Use textContent instead of innerHTML:

    var pscriptText = document.getElementById(divCodeView).textContent;