Bood Carley
Bood Carley

Reputation: 538

Show multiline plain text of textarea?

I just want to show multiline plain text of textarea but I don't want to show the textarea.

Example:

Textarea:

|===================|
| First line        |
| Second line       |
|___________________|

Multiline plain text:

First line
Second line

How can I do this?

Upvotes: 3

Views: 1344

Answers (2)

Oriol
Oriol

Reputation: 287950

You can use <pre>, which defines preformatted text and preserves both spaces and line breaks:

var txt="First line\nSecond line";
document.body.innerHTML+="<pre>"+txt+"</pre>";

Or if you want to do it with CSS or you want more options about whitespaces and linebreaks, you can use CSS property white-space:

Javascript:

var txt="First line\nSecond line";
document.getElementById('mydiv').innerHTML=txt;

CSS:

#mydiv{white-space:pre;}

Upvotes: 4

Rajat Singhal
Rajat Singhal

Reputation: 11254

CSS for textarea:

textarea { 
    border-style: none; 
    border-color: Transparent; 
    overflow: auto;        
  }

Upvotes: 2

Related Questions