11

I would like to have more than one button. I tried to copy code between brackets but doesnt work.Ideas?

buttons: {

"Close": function() {
 $(this).dialog("close");

}

2 Answers 2

35

Create them using this format, 'button text': function() { } with a comma inbetween, like this:

$("#mydialog").dialog({
  buttons: {
    'Confirm': function() {
       //do something
       $(this).dialog('close');
    },
    'Cancel': function() {
       $(this).dialog('close');
    }
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent solution for beginners like me. Thank you very much. I am always so confident to learn new technology; why because I know that stackoverflow can show answer to the problem I am facing...
5

To add to this, the button array method is useful to know about as it exposes more functionality per button, such as adding icons and other per-button properties. The points to note being the added square brackets around the set of buttons turning it into an array of buttons, and the extra curly braces 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');
    }
  }]
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.