jquery output text in htmlentities except line break

    var t = 'hello /n world';

I have a button, it replace string after click.

if I use text() it will convert all string into htmlentites and I can't keep line break

if I use html() I will get xss attack)

(var t should be text data fetch out from database)

any suggestion?


try using :

var t = 'hello /n world';
t = t.replace(/\/n/g, "\n")
$('.word')[0].innerText = t;

as \n should be used for new line character.

Need Your Help

Big-O Hierarchy and comparisons


Which are the corrent hierarchy between above. is that correct?

How do you collect input and store it as a var in html


This is my short chunk of code and I'm trying to learn html and this seems right but it doesn't work. I'm not sure whats incorrect.