How come $(this) is undefined after ajax call

前端 未结 5 1790
无人共我
无人共我 2020-12-21 15:38

I am doing an ajax request when an anchor tag is clicked with an ID set to href. Btw, this anchor tag is dynamically created.



        
5条回答
  •  长情又很酷
    2020-12-21 16:29

    You are in the AJAX function, so your have to assign the $(this) of the click function to a variable first if you want to use $(this) there

    $('.commentDeleteLink').live('click', function(event) {
        ....
        var current = $(this);
        $.ajax({
            // You can use current here
        });
    });
    

提交回复
热议问题