Before reading this article, I highly recommend reading the previous part of the series:
- JQueryUI - Day 1
- JQueryUI - Day 2 (Draggable)
- JQueryUI - Day 3 (Droppable)
- JQueryUI - Day 4 (Resizable)
- JQuery UI - Day 5 (Selectable)
- JQuery UI - Day 6 (Accordion)
- JQuery UI - Day 7 (AutoComplete)
- JQueryUI - Day 8 (Datepicker)
jQuery Dialog opens content in an interactive overlay. Dialog boxes are one of the nicest ways of presenting information on an HTML page. We can define dialog as a floating window with a title and content that can be moved in any direction or may be resized.
Syntax:
$(selector, context).dialog(options);
Or
$(selector, context).dialog("action", [params]);
Example:
- <!DOCTYPEhtml>
- <head runat="server">
- <title></title>
- <link href="http://code.jquery.com/ui/1.10.4/themes/blitzer/jquery-ui.css" rel="stylesheet">
- <script src="http://code.jquery.com/jquery-1.10.2.js">
- </script>
- <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js">
- </script>
- <script>
- $(document).ready(function()
- {
- $("#dialog-1").dialog({
- autoOpen: false,
- buttons: [
- {
- text: "Ok",
- icons:
- {
- primary: " ui-icon-mail-closed"
- },
- click: function() {
- $(this).dialog("close");
- }
- }
- ]
- });
- $("#show").click(function()
- {
- $("#dialog-1").dialog("open");
- });
- });
- </script>
- <style>
- #datepicker-1 {
- margin-top: 20px;
- }
- #div1 {
- background-color: coral;
- color: ButtonHighlight;
- font-size: 30px;
- height: 450px;
- width: 1000px;
- text-align: center;
- margin-left: 150px
- }
- #show {
- font-size: 20px;
- background-color: #14E058
- }
- </style>
- </head>
- <body>
- <div id="div1">
- <span>************Dialog*************</span>
- <div class="ui-widget">
- <div id="dialog-1">
- <h1>Dialog Box</h1>
- <br/>
- <span>This is a simple dialog Example</span>
- </div>
- <input id="show" type="button" value="Show Dialog" "/>
- </div>
- </div>
- </body>
- </html>
Output:

Options:
Option | Description | Example |
autoOpen | If set to | $("#dialog-1").dialog({ autoOpen: false }); |
button | Specifies which buttons should be displayed on the dialog. These are listed as objects, and each property is the text on the button. | $("#dialog-1").dialog({ buttons: [ { text: "Ok", icons: { primary: " ui-icon-mail-closed" }, click: function () { $(this).dialog("close"); } } ] }); |
closeOnEscape | Specifies whether the dialog should close when it has focus and the user presses the escape (ESC) key. | $("#dialog-1").dialog({ closeOnEscape: false }); |
closeText | Specifies the text for the close button. | $("#dialog-1").dialog({ closeText:"Close" }); |
dialogClass | The specified class name(s) will be added to the dialog, for additional theming. | $("#dialog-1").dialog({ dialogClass: "alert" }); |
draggable | If set to false dialog box will not be draggable by clicking and dragging the title bar. | $("#dialog-1").dialog({ draggable: false }); |
height | The height of the dialog. | $("#dialog-1").dialog({ height: 300 }); |
hide | This option is used to set the effect to be used when the dialog box is closed. By default its value is null. | $("#dialog-1").dialog({ hide: { effect:"explode", duration: 1300 } }); |
maxHeight | The maximum height to which the dialog can be resized. | $("#dialog-1").dialog({ maxHeight: 400 }); |
maxWidth | The maximum width to which the dialog can be resized. | $("#dialog-1").dialog({ maxWidth: 400 }); |
minHeight | The minimum height to which the dialog can be resized. | $("#dialog-1").dialog({ minHeight: 600 }); |
minWidth | The minimum width to which the dialog can be resized | $("#dialog-1").dialog({ minWidth: 600 }); |
modal | If this option is set to true the dialog will have modal behavior and other items on the page will be disabled. | $("#dialog-1").dialog({ modal:true }); |
position | Specifies where the dialog should be displayed when opened. Default value is | $("#dialog-1").dialog({ position:{ my: "center", at:"center", of: window } }); |
resizable | If set to true then dialog box can be resized. By default its value is true. | $("#dialog-1").dialog({ resizable: false }); |
show | Define If and how to animate the showing of the dialog. By default its value is null. | $("#dialog-1").dialog({ show: { effect: "blind", duration: 500 } }); |
title | Specifies the title of the dialog. | $("#dialog-1").dialog({ title: "Dialog Box" }); |
width | The width of the dialog in pixels. | $("#dialog-1").dialog({ width:400 }); |
Methods:
Method | Description | Example |
close() | Closes the dialog. | $("#dialog-1").dialog("close"); |
destroy() | Removes the dialog functionality completely. This will return the element back to its pre-init state. | $("#dialog-1").dialog("destroy"); |
instance() | Retrieves the dialog's instance object. | Varobj=$("#dialog-1").dialog("instance"); |
isOpen() | Check whether the dialog is currently open. | Varobj=$("#dialog-1").dialog("isOpen"); |
moveToTop() | Moves the dialog to the top of the dialog stack. | $("#dialog-1").dialog("moveToTop"); |
open() | Opens the dialog. | $("#dialog-1").dialog("open"); |
option(option_Name) | Gets the value currently associated with the specified | Varobj=$("#dialog-1").dialog("maxHeight"); |
option() | Gets an object containing key/value pairs representing the current dialog options | Varobj=$("#dialog-1").dialog(); |
option(option_name,value) | Sets the value of the dialog option associated with the specified | Varobj=$("#dialog-1").dialog("maxHeight",100); |
widget() | Returns a | $("#dialog-1").dialog("widget"); |
Events:




Santhakumar MunuswamyPosted Jan 17, 2016, 2:28 PM
Thanks for nice share
Muhammad Aqib ShehzadPosted Jan 17, 2016, 2:54 AM
good one
Shubham KumarPosted Jan 16, 2016, 1:02 PM
nice! not read fully but i do asap :)
Pankaj Kumar ChoudharyPosted Jan 15, 2016, 8:21 PM
Thanks Nanddeep Nachan Sir...........
Pankaj Kumar ChoudharyPosted Jan 15, 2016, 8:20 PM
Thanks Debasis Saha Sir...........
Pankaj Kumar ChoudharyPosted Jan 15, 2016, 8:20 PM
Thanks Gowtham K Sir..........
Nanddeep NachanPosted Jan 15, 2016, 8:12 AM
Nice share
Debasis SahaPosted Jan 15, 2016, 6:17 AM
Good One..
Gowtham KPosted Jan 14, 2016, 8:51 PM
Good One, Thanks for sharing