Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're seeing <code>\n</code> create a new line because you're inside a <code>&lt;pre /&gt;</code> tag; normally you have to use a <code>&lt;br /&gt;</code> to see a similar new line outside of <code>&lt;pre /&gt;</code>.</p> <p>When you call <code>document.write</code> before the page has finished loaded, the output is entered inplace; so you'll see your <code>FirstText \n SecText</code> written within the <code>&lt;pre /&gt;</code>.</p> <p>However, when it's called <em>after</em> the page has loaded (within <code>setInterval</code>), the existing page is cleared <em>before</em> the result is written; hence <code>&lt;pre /&gt;</code> is being removed, and you're not seeing your new line any more. </p> <p>As you're not closing the <code>document</code> using <code>document.close()</code>, successive calls to <code>document.write</code> in your <code>setInterval</code> are adding to the document stream opened by the <em>first</em> iteration of <code>setInterval</code>.</p> <p>You can fix this by using a <code>&lt;br /&gt;</code> rather than <code>\n</code>;</p> <pre><code> &lt;script&gt; function text(){ document.write("FirstText &lt;br /&gt; SecText &lt;br /&gt;"); } setInterval(text, 1000); &lt;/script&gt; </code></pre> <p>For more info, see <a href="https://developer.mozilla.org/en-US/docs/Web/API/document.write" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/document.write</a> and <a href="https://stackoverflow.com/questions/10873942/document-write-clears-page">document.write clears page</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload