Vani
Vani

Reputation: 1353

How to add line breaks while adding text to div tag

All, I am working on populating a div tag with text.

var centName;
 centName=centName+$(this).attr('data-centerName');//tried <br/> / '\n'

 $("#selOccs").text(centName.Trim(';'));

My div tag is like

  <div ID="selOccs" NAME="selOccs"  style="width: 350px; height: 100px;border:1px solid ;
                   overflow-y: scroll; scrollbar-arrow-color: blue; scrollbar-face-color: #e7e7e7; scrollbar-3dlight-color: #a0a0a0; scrollbar-darkshadow-color: #888888">

   </div>

The issue is adding line breaks. I need display the centName with line breaks.so far all the values are coming in one line[ as per the code].

I tried adding <--br/--> and '\n' but itseems to be not working..

Upvotes: 0

Views: 11491

Answers (2)

Anthony Simmon
Anthony Simmon

Reputation: 1607

var centName;

centName = centName + $(this).attr('data-centerName') + '<br/>';

$("#selOccs").html(centName.Trim(';'));

Upvotes: 2

VVV
VVV

Reputation: 7593

Use .html() instead of text and in the string you can then use <br/>

Upvotes: 7

Related Questions