2

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

0

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

4

Replace

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

use :

$(this).dialog('close')

3 Comments

I've changed it to this, but it still doesn't seem to work. I've added a jsFiddle to my original post.
you're right! I don't know why... but if you remove this lines : $('button').click(function() { $('#message').dialog('open'); and make the dialog autoOpen : true... then the close button work! Maybe there is something in the button script that make js not valid...
Thanks for checking into this again but it was a rather careless mistake on my part. I didn't assign my button an id, so every time I clicked the "cancel" button it would try to open the dialog box again!
2

It's the line:

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

Change it to:

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

Comments

1

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.

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.