Remove element after fading

Remove element after fading

Hello,

On a plugin I have the following:

  1. var defaults = {         
  2.   hide: function ($element, $tooltip) {
  3.     $tooltip.fadeOut(4000);
  4.   }
  5. };
  6. $(this).each(function (e) {
  7.   $this.mouseleave(function (e) {
  8.     tooltip.timer = setTimeout(function () {
  9.       options.hide($this, $("." + options.class).stop(true, true), function () {
  10.         $("." + options.class).remove(); // THE ELEMENT IS NOT BEING REMOVED
  11.       });         
  12.     }, 0);
  13.   }), // Mouse leave 
  14. })

On mouse leave I am trying to remove the element after the animation ends.

The problem is that the element is not being removed. But it works if I use:

  1.   $this.mouseleave(function (e) {
  2.     tooltip.timer = setTimeout(function () {
  3.       options.hide($this, $("." + options.class).stop(true, true));
  4.       $("." + options.class).remove(); // THE ELEMENT IS BEING REMOVED
  5.     }, 0);
  6.   }), // Mouse leave 

Then everything works fine ... Why is function() { ... } disable the remove action?

Thank You,
Miguel