1
I made this html preview, it works very well for my purpose but the first element is appearing as text, and this is a bad result, I understand very little of jquery and javascript, I’m starting to study, I would like to understand what is going wrong.
Put <div></div>
the opening tag appears: <div>
, but only the first, the rest of the code does not appear
Snippet to better understand
function showPreview()
{
var value = $('#copy').val().trim();
value = value.replace("<", "<");
value = value.replace(">", ">");
$('#preview').html(value);
}
textarea {
resize:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="copy" onInput="showPreview();"><div><img src='https://i.imgur.com/FfInIT9.jpg' width='100'/></div>
</textarea>
<br>
<div id="preview"/>
How so but the first element is appearing as text?
– LeAndrade
if you put
<div></div>
the opening tag appears:<div>
– user117425
You don’t want any tag openings to appear?
– LeAndrade
yes, run the snippet and paste:
<div><div><div>
you will see that only the first<div>
appears– user117425