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?
The line breaks are still there, it is just that the browser tries to render them.
If you still want to see the "\n" try this:
var v = $('td:first-of-type').attr('title').replace(/\n/g, "\\n");
Else, if what you want is NOT to see the "\n" and instead see the line breaks, you could do it this way:
var v = $('td:first-of-type').attr('title').replace(/\n/g, "<br/>");
Check this JSBin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With