Damkulul
Damkulul

Reputation: 1476

change from \n to <br> doesn't work using .html()

This question has been asked many times on this website, I tried many examples but nonthing worked. My case is :

Info.find('description').html(Info.description);

I get output like this : Michelle\nma belle These are words that go together well.

I can't replace the \n with <br> (the output is for HTML page) I tried all of these options but I get the same output, do I miss something?

Info.find('description').html(Info.description).replace(/\n/g, "<br />");
Info.find('description').html(Info.description.replace(/\n/g, "<br />"));
Info.find('description').html(Info.description.toString().replace(/\n/g, "<br />"));)
Info.find('description').html(Info.description).replace(**"**\n**"**, **"**<br />**"**));;    
Info.find('description').html(Info.description).replace(new RegExp('/\n','g'), '<br />')

Upvotes: 0

Views: 84

Answers (1)

m87
m87

Reputation: 4523

you just need to add double backslash \\ before n.

Info.find('description').html(Info.description).replace(/\\n/g, "<br>");

** using single backslash \ means escaping a character in regex. so, you were just matching n instead of \n

Upvotes: 1

Related Questions