Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 499
Shaan Avatar asked Jan 20 '26 15:01

Shaan


1 Answers

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

like image 147
Rino Raj Avatar answered Jan 23 '26 05:01

Rino Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!