title: How to document.write() within an image src string? Doesn't get parsed
body: <p>This is for a Javascript application that is only intended to run on a local machine, accessing many large image files from local disk.</p>
  
  <p>Original code like this:</p>
  
  <pre><code>&lt;script&gt;
  // Constants, var inits, etc.
  &lt;/script&gt;
  
  &lt;-- Then html stuff including some control buttons, each one like this --&gt;
  &lt;img id="pgb_runStop" onclick="click_runStop()" src="buttons/but_run.png"&gt;
  
  &lt;--then a chunk of javascript related to the buttons --&gt;
  </code></pre>
  
  <p>The thing works OK, see <a href="http://everist.org/NobLog/20150424_js_animated_gallery.htm" rel="nofollow">http://everist.org/NobLog/20150424_js_animated_gallery.htm</a></p>
  
  <p>Now I want to extend it, so all image pathnames are defined as js constants and vars.
  Some will remain fixed during lifetime of the browser page, others will change by
  user actions.
  I'm stuck with one part of this.
  How to get the html parser to pay attention to script blocks WITHIN &lt;img  .... > statements?</p>
  
  <p>Specifically, I want to do a document.write() within the image src string.</p>
  
  <pre><code>Like: &lt;img src="&lt;script&gt;document.write(B_PATH)&lt;/script&gt;something.png"&gt;
  </code></pre>
  
  <p>This is for the initial page display. The images later get changed by scripts, and that's working OK.</p>
  
  <p>But the html parser doesn't seem to notice scripts inside html elements.</p>
  
  <p>I'm a javascript nubie, so I may have some stupid misconception of how it all works.
  Am I just doing it wrong, or is this fundamentally impossible due to reasons?</p>
  
  <p>Here's an example:</p>
  
  <pre><code>&lt;script&gt;
  // Constants
  PGL_BUT_PATH = "buttons/"      // where the button images etc are.
  &lt;/script&gt;
  
  &lt;-- some html stuff --&gt;
  
  &lt;-- including some control buttons, each one like this --&gt;
  &lt;img id="pgb_runStop" onclick="click_runStop()"
  src="&lt;script&gt;document.write(PGL_BUT_PATH);&lt;/script&gt;but_run.png"&gt;
  
  &lt;--then a chunk of javascript related to the buttons --&gt;
  </code></pre>
  
  <p>In debugger, the img element appears as:</p>
  
  <pre><code>  &lt;img id="pgb_runStop" onclick="click_runStop()"
    src="&lt;script&gt;document.write(PGL_BUT_PATH);&lt;/script&gt;but_run.png"/&gt;
  </code></pre>
  
  <p>The intent was to get this:</p>
  
  <pre><code>  &lt;img id="pgb_runStop" onclick="click_runStop()"
    src="buttons/but_run.png"/&gt;
  </code></pre>
  
  <p>I could just give up with trying to have the page initially render with the correct buttons, and have js correct them afterwards. I'm just surprised... Isn't it possible to evaluate js constants during initial html parsing to construct the DOM, in this way?</p>
  
  <p>Edit to add:
  Sorry, I wasn't clear enough in the question. What I want is a way for js to make the html content/DOM correct (per js config values that get defined very early on) BEFORE the page first renders. To avoid any flicker or resizings after first render.</p>
  
  <p>So another solution would be to delay the first page render till after some scripts have run, so they can make initial DOM adjustments before the user sees anything. Any way to do that?
  Hmmm... actually that would solve another problem I have. I'll try searching for that.</p>
  
  <p>The semantic templating tools suggest are interesting (had never heard of it. <a href="http://www.martin-brennan.com/semantic-templates-with-mustache-js-and-handlebars-js/" rel="nofollow">http://www.martin-brennan.com/semantic-templates-with-mustache-js-and-handlebars-js/</a> ) but am I correct that all such scripting add-ons will execute <em>after</em> the page first renders? </p>