SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the difference between write and writeln?

    I am using both commands in a for loop which types the same phrase 10 times.
    When I use writeln instead of write I get only an extra space and not a new line.
    Am I doing something wrong?
    Thank you in advance.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want a new line, write a <br> tag:

    document.write("some text<br />");

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.writeln() writes a string plus a new-line character. That new-line would show up if you could do View Source on the generated code.

    But new-lines, along with carriage returns, tab characters etc are counted as white-space in HTML. When rendered, any number of consecutive white-space characters are replaced by a single blank.

    So, as jimfraser said, if you want a rendered line break, you need to write the markup for it.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •