Alex Rivera | Logout

How to preserve a line break

Asked 2012-09-15T22:47:20.013
9

Line breaks and carriage returns... Must be the most complicated part of coding. (for me)

Have this code in a page (which came from database stored as This from Ricardo\nAnd also a test\nRent 3000.00):

<td title="This from Ricard
And also a test
Rent 3000.00" style="width:198px;text-align:left">....</td>

Then use this to get the title attribute with 'hidden' \n's

var v = $('#'+i).parent().attr('title');        // i = id of <span> child of <td>

Along the way, the line breaks get lost and using the variable v into a text input box:

This from RicardAnd also a testRent 3000.00

What does it take to preserve the \n's and have this look instead like below?

Screenshot of desired result (with \n's present) after clicking edit

Edit
Report

1 Answer

1

Well, if you put the string into a text input box, there will be no new lines since the text input box is for single-line only text.

The \n are there - you can try splitting by them:

lines = str.split("\n")
answered 2012-09-15T23:00:48.233

Your Answer