5

I want to show a long paragraph of string into a table cell using bootstrap. It contains some newline characters \r\n. I tried to use style="white-space:pre" as this stackoverflow post suggests but that breaks bootstrap text wrap. I also tried to change \r\nto <br> but it does not work. <br> shows up as a text.

This is how my table looks like..

<table id="table1" class="table table-bordered">
    <tbody>
        <tr>
            <th class="col-md-2" scope="row">Description</th>
            <td id="description">Very long test with \r\n so I want to show this in multiline and also want to wrap the text using bootstrap.</td>
        </tr>
    </tbody>
</table>
Community
  • 1
  • 1
E.K.
  • 4,179
  • 8
  • 30
  • 50

1 Answers1

5

Changing the pagebreaks to HTML breaks (br tag) works fine in jsfiddle. See my link below. Make sure that when you are generating the HTML you are generating actual < and > symbols, and not the HTML codes.

https://jsfiddle.net/joedonahue/zpj94p0b/

<table id="table1" class="table table-bordered">
    <tbody>
        <tr>
            <th class="col-md-2" scope="row">Description</th>
            <td id="description">Very long test with <br/> so I want to show this in multiline and also want to wrap the text using bootstrap.</td>
        </tr>
    </tbody>
</table>
atjoedonahue
  • 476
  • 6
  • 19
  • hmmmm yes you are right. Based on your feedback found out that my problem was this jquery code `$('#description').text('this\n has\n newlines);` My solution here, http://stackoverflow.com/questions/4535888/jquery-text-and-newlines Thank you! – E.K. Jul 08 '16 at 23:43