6

I have been using JQuery UI dialog box.The following code I am using.Can any one please let me know how to hide the Export button after click

$( "#dialog-confirm1" ).dialog({
            resizable: false,
            height:350,
            width:650,
            modal: false,
            autoOpen:false,
            buttons: {
                "Export": function() {
                    exportCSV(2);


                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
1
  • When you say "hide the Export button", you mean leave the dialog box open with only the cancel button? Commented Jul 28, 2011 at 12:40

3 Answers 3

9

You could use $('.ui-button:contains(Export)').hide(): (the following code hides the export button when you click it)

$( "#dialog-confirm1" ).dialog({
            resizable: false,
            height:350,
            width:650,
            modal: false,
            autoOpen:false,
            buttons: {
                "Export": function() {
                    exportCSV(2);
                    $(event.target).hide();


                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
Sign up to request clarification or add additional context in comments.

3 Comments

Hi,Nicola Thanks, it works.But forgot to tell.I do have two dialog boxes dialog-confirm1 and dialog-confirm0 and both have "Export" button and when I click Export button of dialog-confirm1 dialog box it also hides Export button of dialog-confirm dialog box.Thanks, Ravi
@Ravi i think that the better option is what Frédéric Hamidi pointed out, use event.target (i updated my answer to use it)
event.target goes to the span inside the button, not the button itself. Use: $(event.target).parent().hide(); instead.
4

The documentation for the buttons option says:

The context of the callback is the dialog element; if you need access to the button, it is available as the target of the event object.

Therefore, you can use event.target to refer to the button element:

buttons: {
    "Export": function(event) {
        $(event.target).hide();
        exportCSV(2);
    },
    "Cancel": function() {
        $(this).dialog("close");
    }
}

1 Comment

Use $(event.target).parent().hide(); instead. At least for me, the target is the span inside the button.
0
buttons: [{
    "Export": function() { exportCSV(2); },
    click: $( this ).hide()

}]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.