title: Firefox XUL toolbar problem with javascript getElementById
body: <p>I'm writing my first Firefox XUL toolbar, and am getting a strange behavior - in order to debug my code, I call the same js function from both the firefox toolbar and from a button on a very simple HTML file I created.</p>
  <p>The javascript function displays an alert window, gets an element using 'document.getElementById', changes its color, and displays another alert window.</p>
  <p>The javascript function works well when called using the HTML button, but when using the toolbar button the 'document.getElementById' returns null and the function terminates (only the first alert window shows).</p>
  <p>Any guess what can be wrong? I provide the (very simple) code below for refenrece.</p>
  <p>Many thanks in advance!</p>
  <h2>The javascript file - facebrew.js</h2>
  <pre><code>function FaceBrew_rtlSelection() {
      alert('Before!'); 
    sel_node = document.getElementById(&quot;header&quot;);
      sel_node.style.color = 'blue';
      alert('After!'); 
  }
  </code></pre>
  <h2>The HTML file</h2>
  <pre><code>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  
  &lt;head&gt;
  &lt;title&gt;Test&lt;/title&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;http://localhost/Sandbox/FaceBrew/chrome/content/facebrew.js&quot;&gt; &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;input type=&quot;button&quot; value=&quot;Click me&quot; id=&quot;select&quot; onclick=&quot;FaceBrew_rtlSelection()&quot; /&gt;
  &lt;div id=&quot;header&quot;&gt;
    &lt;h1&gt;Hello world!&lt; /h1&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <h2>The XUL file - facebrew.xul</h2>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;?xml-stylesheet href=&quot;chrome://facebrew/skin/facebrew.css&quot; type=&quot;text/css&quot;?&gt;
  
  &lt;overlay id=&quot;FaceBrew-Overlay&quot;
           xmlns=&quot;http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&quot;&gt;
  
      &lt;script type=&quot;application/x-javascript&quot;
              src=&quot;chrome://facebrew/content/facebrew.js&quot; /&gt;
           
      &lt;toolbox id=&quot;navigator-toolbox&quot;&gt;
          &lt;toolbar id=&quot;FaceBrew-Toolbar&quot; toolbarname=&quot;FaceBrew Toolbar&quot; accesskey=&quot;F&quot;
                   class=&quot;chromeclass-toolbar&quot; context=&quot;toolbar-context-menu&quot; 
                   hidden=&quot;false&quot; persist=&quot;hidden&quot;&gt;
              &lt;toolbaritem flex=&quot;0&quot;&gt;            
                  &lt;toolbarbutton id=&quot;FaceBrew-Web-Button&quot; tooltiptext=&quot;&quot;
                                 label=&quot;Run&quot; oncommand=&quot;FaceBrew_rtlSelection()&quot; /&gt;
              &lt;/toolbaritem&gt;
          &lt;/toolbar&gt;
      &lt;/toolbox&gt;
  &lt;/overlay&gt;
  </code></pre>
  <h2>The CSS file - facbrew.css</h2>
  <pre><code>#FaceBrew-Web-Button {
      list-style-image: url(&quot;chrome://facebrew/skin/web.png&quot;);
  }
  </code></pre>