Vecta
Vecta

Reputation: 2350

jQuery UI Dialog—Close Button Not Working

I'm having some trouble getting the close button on my dialog box to work. I followed an example I found, but mine won't close. What am I doing wrong?

$(function() {
    $('#message').dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        buttons: {
            'Okay': function() {
                document.location = 
                    'http://www.google.com';
                    },
            'Cancel': function() {
            ('#message').dialog('close');
        }
        }
    });

    $('button').click(function() {
        $('#message').dialog('open');
    });
});

jsFiddle

Upvotes: 2

Views: 9782

Answers (4)

Vecta
Vecta

Reputation: 2350

Since my click event is referring to a general button, hitting the cancel button essentially opened the dialog again. I gave the button an id and referenced that.

Upvotes: 1

Malevolence
Malevolence

Reputation: 1857

It's the line:

'Cancel': function() { ('#message').dialog('close'); }

Change it to:

'Cancel': function() { $(this).dialog('close'); }

Upvotes: 2

2GDev
2GDev

Reputation: 2466

Replace

('#message').dialog('close');

use :

$(this).dialog('close')

Upvotes: 4

Daff
Daff

Reputation: 44215

You forgot the $. It is

$('#message').dialog('close'); 

I recommend using a developer tool like Firebug. It will display a detailed error message in the console.

Upvotes: 4

Related Questions