Nils Anders
Nils Anders

Reputation: 4420

jQuery bootbox dialog

I try to get the following code to work

//===== Dialogs =====//
$(".table a.delete").click(function (e) {
    e.preventDefault();
    bootbox.confirm("Are you sure?", function (confirmed) {
        if (confirmed) {
            var $el = $(this);
            var $tr = $el.closest('tr');
            var url = $el.closest('table').data('remove-url');
            var id = $tr.data('id');

            $tr.fadeOut(function () {
                $el.remove();
                $.post(url, { id: id }); // do the delete on the server 
            });
        }
    });
});

The bootbox is showing, but the code below if(confirmed) doesnt run.

Upvotes: 0

Views: 608

Answers (1)

hank
hank

Reputation: 3768

$(this) inside the anonymous bootbox-method does not refer to what you think it does. The code inside if (confirmed) is executed but does not match anything.

$(".table a.delete").click(function (e) {
    var $el = $(this);
    e.preventDefault();

    bootbox.confirm("Are you sure?", function (confirmed) {
        if (confirmed) {
            var $tr = $el.closest('tr');
            ... etc
        }
    });
};

Upvotes: 2

Related Questions