2
How do I treat input text as a string even if they are html tags?
Ex: if I type
<b>texto</b>
in an untreated input field it appears like this text, but I want it written anyway:
<b>texto</b>
2
How do I treat input text as a string even if they are html tags?
Ex: if I type
<b>texto</b>
in an untreated input field it appears like this text, but I want it written anyway:
<b>texto</b>
4
In pure javascript you can do so:
texto.onkeyup = function() {
resultado.textContent = this.value
}
<input type="text" id="texto">
<div id="resultado">
</div>
In jQuery:
$('#texto').keyup(function() {
$('#resultado').text($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="texto">
<div id="resultado"></div>
legal, simple and practical. In this case the secret is in textContent
?
Exactly, instead of using innerHTML, uses textContent, which ignores the interpretation of tags, put an example with jquery also!
Perfect, great fight!
Browser other questions tagged javascript html
You are not signed in. Login or sign up in order to post.
You’re doing it with pure javascript or jquery?
– JuniorNunes
jQuery for the most part, but the easiest thing for you will already help me.
– Luiz Augusto Neto