Hi all,

I'm puzzled with the following code (context explained below) :

$(document).ready(function() {
        var modal = $("#modal_yesno")[0];
        $(".a_delete").css("cursor", "pointer").click(function() {
                var tr = $(this).parent().parent();
                var id = $(tr).attr("id").replace("item_", "");
                console.log(id);        // first console log
                $("#modal_yes").click(function() {
                        console.log(id);        // second console log
                        $.unblockUI();
                });
                $("#modal_no").click($.unblockUI);
                $.blockUI(modal, { width: '275px' });
        });
});


Explanation of the context :

This code is used in an listing html table. Last td of each row
contains an image with class="a_delete". I apply the click() block
here before. The first lines of the block keeps variable tr  which is
the <tr> row parent of the image. I take of the id attribute in order
to get the ID of the row. As the purpose of this is to delete the row,
I want a confirmation using BlockUI. #modal_yes is the "YES" button in
the modal div. My problem is that when the code is triggered, the
first block extract the id correctly and the second one have the good
ID the first time. But when I click again on another row, the first
part have the good id but the BlockUI block still uses the old ID.
Seems that this block have always the old variable scope but I don't
understand why. Can someone enlighten me before I go nuts ?

Console log output :

# I click on row with id 618 :

618   # first console log
618   # second console log

# now I click on row with id 620

620   # first console log
618   # second console log


Thanks.




--
Fabien Meghazi

Website: http://www.amigrave.com
Email: [EMAIL PROTECTED]
IM: [EMAIL PROTECTED]

Reply via email to