0

I have a textarea where i get it's content and send it to database via ajax. When i get such content and insert it in a DIV, new lines are not considered, so the content is pasted as a whole without LF.

I used jQuery templates for printing the result of my query and within the template the mentioned div is:

<div class="message">${msg}</div>

where ${msg} is the message gathered from the database with CR.

Is there anything I could do for avoiding that?

4
  • Do a find and replace? Replace CR with CRLF. Commented Jun 20, 2012 at 21:12
  • The question is that I want to show the new lines when the message is placed into the div. Commented Jun 20, 2012 at 21:16
  • Did you inspect the resulting div with Firebug? If the <br /> are here there should by newlines... Commented Jun 20, 2012 at 21:34
  • <br /> is printed when the message is inserted into the div. Commented Jun 21, 2012 at 7:44

1 Answer 1

2

You use php, do you? So you can convert normal line breaks (\n) to HTML line breaks (<br />) with nl2br().

Sign up to request clarification or add additional context in comments.

1 Comment

I have just used such function and in the database are replaced with <br /> but when i put the content within the div, happens the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.