tags:

views:

417

answers:

2

i have some content like this

var p =  

 i myself
 Abhimanyu Singh
 Yadav

when i m trying to insert into as innerHTML to some div the whole content appears in one line.i m using <pre> tag to avoid this problem.but need some appropriate solution.

+4  A: 

You can replace the new line characters with html BR elements (<br />):

document.getElementById('myDiv').innerHTML = p.replace(/\n/g, '<br />');
CMS
+1  A: 
var p = "i myself<br />Abhimanyu Singh<br />Yadav";

updated to make andrew happy. a still non-semantic answer that is more semantic.

Jason
Totally non-semantic. A terrible idea. It will style as a paragraph break instead of a line-break.
Andrew Moore
yes, it appears this OP is worried about semantics, first off, as he is trying to insert line breaks in completely random places. when a user asks something ridiculous like this, i give an answer that works. if he wants to replace the `<p>` tags w/`<br />` tags, whatever
Jason