title: Is there a php echo/print equivalent in javascript
body: <p>Say I want to print html from inside a script tag.</p>
  
  <p>A source like this</p>
  
  <pre><code>&lt;div&gt;foo&lt;/div&gt;
  &lt;script&gt;
  print('&lt;div&gt;Print this after the script tag&lt;/div&gt;');
  &lt;/script&gt;
  &lt;div&gt;bar&lt;/div&gt;
  </code></pre>
  
  <p>should look something like this in browser after the script has run</p>
  
  <pre><code>&lt;div&gt;foo&lt;/div&gt;
  &lt;script&gt;
  print('&lt;div&gt;Print this after the script tag&lt;/div&gt;');
  &lt;/script&gt;
  &lt;div&gt;Print this after the script tag&lt;/div&gt;
  &lt;div&gt;bar&lt;/div&gt;
  </code></pre>
  
  <p>I could write my own code for this purpose but since this looks to me like a very simple problem, I'm guessing either I've missed something or my thinking is flawed in some way and printing is left out intentionally.</p>
  
  <p>Also, somewhat related: I'd like to know if a script is (or can be made) aware of the script tags surrounding it. With this information it would be much easier to find the position for the printed html code to be injected into, assuming it's not highly discouraged.</p>
  
  <p>To clarify: I don't need you to write a print function for me. I only need to know if a native method to achieve this exists and I've missed it or alternatively the reason it shouldn't be done.</p>
  
  <p><strong>EDIT</strong>
  I realized that I didn't think the question through.</p>
  
  <p>I got my facts straight and now almost everything seems to be working. I should've originally mentioned that the print function was needed inside templates - I'm working on a template engine experiment. I managed to work it out by separating scripts from plain html and concatenating the split html sans scripts with script output.</p>
  
  <p>As I was writing the code I noticed that everything wouldn't go so smooth because of the asynchronous nature of js. I guess I was expecting to be able to do any kind of js magic in templates, just like I could in php. Seems like actually supporting async code in a fool-proof manner inside templates will require some more thought.</p>