Shaan Shaan - 1 year ago 69
HTML Question

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

I am trying to enable manual line breaks in

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
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 Source

Please try this

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

this will covert all enter key pressed to line break


You can use 'pre' tag.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download