If i write something like below inside textarea
<strong>test</strong>
inside textarea and then display it inside a div. It shows the text in bold letter instead of showing the html code as it is. So how can i avoid rendering html code. I just want to show as it is the text was entered by user.
You haven't shown us any code, but since you have tagged this jQuery I'll assume you have something like:
$('div').html(
$('textarea').val()
);
Use the text method instead, so what the user has typed is treated as text instead of HTML.
$('div').text(
$('textarea').val()
);
See a demonstration.
You need to escape the < and > characters to their HTML entities.
<strong>test</strong>
JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With