[英]get html element from a string and append it in a div
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:我被一个代码困住了,我必须使用一个 html 字符串才能从中获取原始 html。我的 html 字符串如下所示:
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> </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需要去除双引号以获取 html 元素并将它们插入一个 div.like 如下作为原始元素不被双引号包围
<p>This is my textarea to be replaced with CKEditor.</p>
<pre>
<code class="language-bash">CKEDITOR.instances.editor1.getData()</code></pre>
<p> </p>
and i don't want to use innerHTML property.Any help in this regard will be higly appreciated :)我不想使用 innerHTML 属性。在这方面的任何帮助将不胜感激:)
You can use single quotes for the string and turn it into DOM element:您可以对字符串使用单引号并将其转换为 DOM 元素:
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> </p>' var d = document.getElementById('result'); d.innerHTML = htmlString;
<div id="result"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.