Receive input code

2

How do I treat input text as string even though they are html tags?

Ex: if I type

<b>texto</b>

In an input field without treatment it appears so text , but I want it written anyway:

<b>texto</b>
    
asked by anonymous 23.01.2017 / 14:38

1 answer

4

In pure javascript you can do this:

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><inputtype="text" id="texto">

<div id="resultado"></div>
    
23.01.2017 / 14:44