-1

i am stuck with a code where i had to work with a html string to get raw html out of it.My html string looks like the following:

var string="<p>This is my textarea to be replaced with CKEditor.</p>

<pre>
<code class="language-bash">CKEDITOR.instances.editor1.getData()</code></pre>

<p>&nbsp;</p>"

need to strip the double quote to get the html elements and insert them in a div.like the following as raw element not enclosed by double quote

<p>This is my textarea to be replaced with CKEditor.</p>

    <pre>
    <code class="language-bash">CKEDITOR.instances.editor1.getData()</code></pre>

    <p>&nbsp;</p>

and i don't want to use innerHTML property.Any help in this regard will be higly appreciated :)

AL-zami
  • 8,902
  • 15
  • 71
  • 130

1 Answers1

0

You can use single quotes for the string and turn it into DOM element:

var htmlString='<p>This is my textarea to be replaced with CKEditor.</p><pre><code class="language-bash">CKEDITOR.instances.editor1.getData()</code></pre><p>&nbsp;</p>'
var d = document.getElementById('result');
d.innerHTML = htmlString;
<div id="result"></div>
jianweichuah
  • 1,417
  • 1
  • 11
  • 22
  • @AL-zami you can do it without jQuery too. Updated the answer. – jianweichuah Dec 23 '15 at 03:24
  • that is the porblem.I am trying to use it without innerHTML. I am working with ckeditor and can't use highlight.js in codesnippet plugin if i append html string via innerHTML..That's why i need to strip the quotes and append raw html tags – AL-zami Dec 23 '15 at 03:29
  • I have not worked with CKEditor but, this may work for you: http://stackoverflow.com/a/5071691/1990536 – Rai Dec 23 '15 at 03:50