jqueryHow do I create a jQuery Yes/No dialog?
Creating a jQuery Yes/No dialog is a simple process. Following is an example code block to do this:
$('#dialog-confirm').dialog({
autoOpen: false,
resizable: false,
height:140,
modal: true,
buttons: {
"Yes": function() {
$(this).dialog("close");
//do something
},
"No": function() {
$(this).dialog("close");
//do something
}
}
});
This code block will create a Yes/No dialog box with two buttons - Yes and No. When the user clicks on any of these buttons, the dialog box will close and the code inside the corresponding function will be executed.
Code explanation
-
$('#dialog-confirm').dialog({
- This initializes the dialog box and all the settings are passed in the form of an object. -
autoOpen: false
- This is used to specify whether the dialog box should open automatically or not. -
resizable: false
- This is used to specify whether the dialog box should be resizable or not. -
height:140
- This is used to specify the height of the dialog box in pixels. -
modal: true
- This is used to specify whether the dialog box should be modal or not. -
buttons: { ... }
- This is used to specify the buttons that should be displayed in the dialog box. -
"Yes": function() { ... }
- This is used to specify the code that should be executed when the user clicks on the Yes button. -
"No": function() { ... }
- This is used to specify the code that should be executed when the user clicks on the No button. -
$(this).dialog("close")
- This is used to close the dialog box.
Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I add a zoom feature to my website using jQuery?
- How do I use jQuery to zoom an image when it is clicked?
- How do I use jQuery to zoom in or out on an element?
- How do I use jQuery to change the z-index of an element?
- How do I use a jQuery zoom plugin?
- How do I use jQuery to zip files?
- How do I download a zip file using jQuery?
- How can I use jQuery to zoom an image when the user hovers over it?
- How do I use jQuery to zoom in on an image?
See more codes...