How to start a new line from JavaScript?


I have created this "shell" in jQuery:

Code: link text

Demo: link text

I need that every 100 chars, the prompt go in a new line below.
How can I do this ?


At a high level, you’re generating html from JavaScript, so any html which would work standalone will work when generated from JavaScript too. Some possibilities, with varying flexibility:

Pre-formatted text, insert newline "\n" characters:

line one
line two

Inserting break tags:

line one<br />
line two<br />

Or my favourite, use paragraph tags:

<p>line one</p>
<p>line two</p>

I like this because you can refer to each line in code as a single DOM element. Set this css to keep the lines side-by-side:

div.code-listing p { margin: 0; padding: 0; }

Answered By – Douglas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published