What I want is that when writing a label in TextArea
which the text written in it is directed towards a <div>
and thus be able to visualize the code in real time.
What I can't do is get the tags to be recognized.
When I put the tags <pre><code> </code></pre>
from the code there it works for me, but not when writing them at runtime from the TextArea
.
$(document).ready(function(){
});
function getTexto(){
var texto = document.getElementById("txtArea").value;
return texto;
}
function escribirCodigo(){
$('#vistaPrevia').text(getTexto());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<center>
<textarea id="txtArea" cols="20" rows="10" onkeyup="javascript:escribirCodigo();"></textarea>
</center>
<div id="vistaPrevia" style="padding: 20px;">
<!-- Aqui se escribe el codigo obtenido del TextArea -->
</div>
It is clear, in your code and no , your line would be
está añadiendo texto empleando el método
text
HTML
But keep in mind that there is no need to use Jquery for this , you could modify the innerHTML property to add new content.
TRY WITH THIS CODE