Search code examples
javascriptjqueryfadein

jQuery get faded element in fadeIn callback


Is there a way to get the element, that I faded, in the callback of a fadeIn? So far i tried $(this) and it does not work, returns document...

Example, here I need access to the class="row" div that I added.

 $('<div class="row allow-drag id=' + id + '"></div>').hide().insertAfter(e.target).fadeIn(600, () => {
    console.log($(this));
});

Solution

  • Arrow functions do not bind it's own 'this' context.

    Use a normal function declaration and it will work.