Charles Okwuagwu
Charles Okwuagwu

Reputation: 10866

append any text to a div using jquery without altering the text

I receive text via SignalR and I can use console.log(s) to view the text perfectly.

I now have a console page, basically a scrolling div, I want to view text unaltered, but

$('#console').append(s);

keeps altering the text content.

sample content in chrome console:

09-09 11:04:36.11 tx:   <body>4384041
user_22BLE:
Ok am a man i live in lagos too</body>
09-09 11:04:36.11 tx:   <offline></offline>

it even retains the line breaks...

Upvotes: 0

Views: 70

Answers (1)

Man Programmer
Man Programmer

Reputation: 5356

encode from html entities then it show similar like console

function htmlEntity(rawStr){
var encodedStr = rawStr.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
   return '&#'+i.charCodeAt(0)+';';
});
    return encodedStr;
}

you can encode html entity from this function

try like this

$('#console').append(htmlEntity(s));

Upvotes: 2

Related Questions