title: How to create jQuery Dialog in function
body: <p>Does anyone know how to create a jQuery Dialog in a function? I can't find an attribute to set the message... In every example I found, the dialog has been statically written into the code in a div-tag. However, I want to create it dinamically, so I need to know how to create a dialog in a function.</p>
  
  <p>It is no problem to set the title:</p>
  
  <pre><code>    &lt;script&gt;
      // increase the default animation speed to exaggerate the effect
      $.fx.speeds._default = 1000;
      $(function() {
          $( "#dialog" ).dialog({
              autoOpen: false,
              show: "blind",
              hide: "explode"
          });
  
          $( "#opener" ).click(function() {
              //$( "#dialog" ).dialog( "open" );
              $( this ).dialog({ title: 'Please confirm deletion!' });
              return false;
          });
      });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  </code></pre>
  
  <p>I have the documentation and some examples <a href="http://jqueryui.com/demos/dialog/#default" rel="noreferrer">here</a>.</p>
  
  <p>Thanks for helping out guys.</p>
  
  <p>Cheers,
  doonot</p>
  
  <p>============================= [SOLUTION]=====================================</p>
  
  <p>Thanks for all who answered this questions. This is how i wanted it:</p>
  
  <pre><code>    function createDialog(title, text) {
      return $("&lt;div class='dialog' title='" + title + "'&gt;&lt;p&gt;" + text + "&lt;/p&gt;&lt;/div&gt;")
      .dialog({
          resizable: false,
          height:140,
          modal: true,
          buttons: {
              "Confirm": function() {
                  $( this ).dialog( "close" );
              },
              Cancel: function() {
                  $( this ).dialog( "close" );
              }
          }
      });
  }
  </code></pre>
  
  <p>And it can be called for example like this (clicking on an image):</p>
  
  <pre><code>&lt;img src="delete.png" onClick="createDialog('Confirm deletion!', 'Do you really want to delete this package?')"&gt;
  </code></pre>