jquery-uidialog

How to create a dialog using jQuery UI without a <div> specified in the HTML code?


Using jQuery UI to create a dialog is pretty easy:

<script>
$(function() {
    $( "#dialog" ).dialog();
});
</script>

<div id="dialog" title="Basic dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be   moved, resized and closed with the 'x' icon.</p>
</div>

But you still need a <div> in the HTML for this to work.

Is it possible to use purely jQuery (without a <div> in the HTML code) to create a dialog?


Solution

  • While I'm not sure why you would want to open a dialog with no content, you could easily create a new one on the fly and invoke the jquery dialog against it:

    $("<div>hello!</div>").dialog();