17

I am using Jquery's dialog() method to create dialog. I am creating buttons on the dialog while creating the dialog, using

      $("#divName").dialog({
            buttons:
            {
            "Cancel":{

I have one event on which I need to hide the button,but don't know which attributes to use. Please tell me the attributes to hide button. Thanks in advance.

Swap905
  • 301
  • 1
  • 3
  • 9

7 Answers7

15

If you're trying to hide the "cancel" button, try this. 

$('.ui-dialog-buttonpane button:contains("cancel")').button().hide();
akiller
  • 2,462
  • 22
  • 30
bang
  • 151
  • 1
  • 5
  • Had some trouble with this until I realized that the parameter ('cancel') is case sensitive (my button was labeled 'Cancel'). – JonV Mar 13 '22 at 06:04
7

When you create the dialog, you describe the buttons and the attributes of the buttons, so add an "id" attribute to the button:

buttons: [ { text: "Save", id: "btnId", click: function() { ... } } ]

You can then use the id as a jquery filter for the hide() and show() methods:

$("#btnId").hide()...

Beau
  • 153
  • 1
  • 5
2

Use:

$('#divName').siblings('.ui-dialog-buttonpane').find('button').eq(n).hide();

where n is the number of the button in your dialog (starting from zero)

Alnitak
  • 334,560
  • 70
  • 407
  • 495
1

Try this.

$("#divName").css("display","none");
bluish
  • 26,356
  • 27
  • 122
  • 180
Akhi
  • 2,242
  • 18
  • 24
  • 1
    that'll hide the whole dialog. – Alnitak Jul 16 '12 at 12:38
  • I've added a hint how you can give the button a ID so it is easier to access it. This way, only the button is hidden and not the entire dialog... ;-) – Matt Apr 09 '13 at 10:59
1

This will hide first button:

$('#divName').siblings('.ui-dialog-buttonpane').find('button:first').hide();
bluish
  • 26,356
  • 27
  • 122
  • 180
0

Try below to get handle to all buttons and then loop through them to hide.

var buttons = $("#divName").dialog('option', 'buttons');
Santosh Gokak
  • 3,393
  • 3
  • 22
  • 24
0

Try this jQuery selector to hide the "cancel" button. Adjust childNodes index according to your buttons order.

$('.ui-dialog-buttonset')[0].childNodes[0].hide();
Tyler2P
  • 2,324
  • 26
  • 22
  • 31