Shaan Shaan - 14 days ago 6
HTML Question

<TD> tag does not consider manual line breaks (or ENTER) in HTML

I am trying to enable manual line breaks in

<td>
tag in HTML.

Content is coming from a file which consists of ENTER or manual line breaks, but while displaying this data in HTML table, data is being displayed continuously. Means it is ignoring manual line breaks.

Is there any way to make
<td>
tag to consider manual line breaks or ENTER you can say?

For example:

Text coming from DataBase:

Line 1.
Line 2.
Line 3.


(with ENTER after each line)

Data displayed in table cell:

Line 1.Line 2.Line 3.


(not considering ENTER after each line)

Tried different ways but failed. Please suggest some solution.

Answer

Please try this

str = str.replace(/(?:\r\n|\r|\n)/g, '<br />');

this will covert all enter key pressed to line break

OR

You can use 'pre' tag.

Reference

Comments