title: Unexplained behavior with script tags being moved in the DOM?
body: <p>I've found some strange behavior trying to reproduce something else and I thought it was interesting. </p>
  
  <p>My jsbin example is <a href="http://jsbin.com/obuney/3" rel="nofollow">here</a></p>
  
  <p>The core code:</p>
  
  <pre><code>  &lt;div id="diag"&gt;
      &lt;script type="text/javascript"&gt;
        $(document).ready(function(){
        if(x==undefined){
          var x=1;
        }else{
          x=x+1;
        }
        alert(x);
        });
      &lt;/script&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>(at the bottom of the page)</p>
  
  <pre><code>$(document).ready(function(){
    $('#diag').dialog();
  });
  </code></pre>
  
  <p><code>$.dialog</code> I know will move this script in the DOM, so it is expected that it will be executed twice. However, the results are different than I would expect.</p>
  
  <p>I expected for it to say 1 and then 2. However, it says 1 and then 1 again. How is that even possible? This behavior is consistent across Firefox5, Chrome, and IE8</p>