title: JQuery Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
body: <p>I am suddenly getting this error from jQuery :</p>
  
  <blockquote>
    <p>Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'</p>
  </blockquote>
  
  <p><strong>Plugins</strong></p>
  
  <pre><code> &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
   &lt;script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"&gt;&lt;/script&gt; 
  </code></pre>
  
  <p><strong>jQuery code</strong>   </p>
  
  <p>I am getting those messages in the following function:</p>
  
  <pre><code>$(document).ready(function() {
    if ($('#results').html().length != 0) {
      alert('has information');
  
      $('#dialog').dialog({
        modal: true,
        buttons: {
          Ok: function() {
            // If I use $(this).dialog($(this)).dialog('close'), the UI is displayed,
            // however I do not see the OK button and no errors 
            $(this).dialog('close');
          }
        }
      });
    } else {
      alert('has no data');
    }
  });
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div id="dialog" title="Server Response"&gt;
    &lt;p&gt;&lt;span class="${icon}" style="float: left; margin: 0 7px 50px 0;"&gt;&lt;/span&gt;
      &lt;label id="results"&gt;${results}&lt;/label&gt;
    &lt;/p&gt;      
  &lt;/div&gt;
  </code></pre>