How to add multiple buttons to a jQuery UI dialog?

I would like to have more than one button. I tried to copy the code between the brackets, but it does not work. Ide?

buttons: { "Close": function() { $(this).dialog("close"); } 
+10
javascript jquery dialog
Mar 25 '10 at 0:50
source share
2 answers

Create them in this format 'button text': function() { } with a comma between them, for example:

 $("#mydialog").dialog({ buttons: { 'Confirm': function() { //do something $(this).dialog('close'); }, 'Cancel': function() { $(this).dialog('close'); } } }); 
+32
Mar 25 '10 at 0:53
source share

To add to this, the button array method is useful to know because it provides more functionality for each button, for example, adding icons and other properties for each button. It should be noted that the added square brackets around the button set turn it into an array of buttons and additional curly brackets around each button object.

 $("#mydialog").dialog({ buttons: [{ text: 'Confirm', icons: { primary: "ui-icon-check" }, click: function() { //do something $(this).dialog('close'); }},{ text: 'Cancel', icons: { primary: "ui-icon-cancel" }, click: function() { $(this).dialog('close'); } }] }); 
0
Nov 17 '16 at 19:42
source share



All Articles