0

I have this code:

var bt = {}

bt = {
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove()
    }
}, {
    text: "Cancel",
    click: function () {
        $(this).remove()
    }
}

$("#test").dialog({
    title: "Confirm deletion",
    width: "300px",
    buttons: [bt]
})

Why do I only see the OK button, and not the Cancel button?? JSfiddle here.

1 Answer 1

1

That's because your assignment to bt does not do what you think it does. It ends up applying the comma operator and is equivalent to:

bt = {
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove();
    }
};
// Stray, ignored object literal.
{
    text: "Cancel",
    click: function () {
        $(this).remove();
    }
};

If you want bt to be an array, then make it so:

var bt = [{
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove();
    }
}, {
    text: "Cancel",
    click: function () {
        $(this).remove();
    }
}];

$("#test").dialog({
    title: "Confirm deletion",
    width: "300px",
    buttons: bt
});
Sign up to request clarification or add additional context in comments.

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.