Using $(this).addClass is not working in AJAX success

Viewed 2702

I am doing some ajax processing on click event that working fine but now I want to add class on success function I am using $(this).addClass("cover"); but nothing is happening . If I target class for add class mean if I use like this $('.dz-cover').addClass("cover"); it works fine but it add class all link tag that is with class name '.dz-cover' I don't want I just only want to add class only that link in which I am clicking. My code is below

$("#dropzonePreview").on("click", "a.dz-cover", function () {
    var id = $(this).data('id');
    $.ajax({
        type: 'POST',
        url: 'attachment/cover',
        data: {id: id},
        dataType: 'html',
        success: function (data) {
            $(this).addClass("cover");                   
        }
    });
});
3 Answers
Related